Apache is the world’s most popular, cross-platform HTTP web server that is commonly used in Linux and Unix platforms to deploy and run web applications or websites. Importantly, it’s easy to install and has a simple configuration as well.
In this article, we will show how to check Apache web server uptime on a Linux system using different methods/commands explained below.
1. Systemctl Command
systemctl command is a utility for controlling the systemd system and service manager; it is used it to start, restart, and stop services, and beyond.
The systemctl status sub-command, as the name states are used to view the status of a service, you can use it to check the running status of your Apache web server.
$ sudo systemctl status apache2 #Debian/Ubuntu # systemctl status httpd #RHEL/CentOS/Fedora
2. Apachectl Command
The apachectl command is used to control and manage the Apache, which is primarily used for starting, stopping, and restarting the Apache web server, as well as performing other administrative tasks.
$ sudo apachectl start [Start Apache web server] $ sudo apachectl stop [Stop Apache web server] $ sudo apachectl restart [Restart Apache web server] $ sudo apachectl graceful [Gracefully Restart Apache web server] $ sudo apachectl configtest [Check Apache Configuration] $ sudo apachectl -V [Check Apache Version] $ sudo apachectl status [Check Apache Status]
The apachectl command can be used to enable or disable Apache modules, including the mod_status module, which provides an interface that displays information about the Apache web server’s current status and performance.
Enable Apache Server Status in Debian/Ubuntu
The Apache server-status component is enabled by default in the file /etc/apache2/mods-enabled/status.conf configuration file.
$ sudo vi /etc/apache2/mods-enabled/status.conf
<Location /server-status> section, add the following lines to allow access from your IP address or network.
You can also use Require all granted to allow access from all IPs but be cautious about security implications.
Save the configuration file and restart the Apache service to apply the changes:
$ sudo service apache2 restart
Enable Apache Server Status in RHEL Systems
To enable the Apache server-status component in RHEL-based distributions, create a file below.
# vi /etc/httpd/conf.d/server-status.conf
and add the following configuration.
<Location "/server-status"> SetHandler server-status Require ip your_ip_address_or_network </Location>
Save the file and close it. Then restart the web server.
# systemctl restart httpd
If you are primarily using a terminal, then you also need a command-line web browser such as lynx or links.
$ sudo apt install lynx #Debian/Ubuntu # yum install links #RHEL/CentOS
Then run the command below to check the Apache service uptime:
$ apachectl status
Alternatively, use the URL below to view the Apache web server status information from a graphical web browser:
http://localhost/server-status OR http:SERVER_IP/server-status
3. ps Command
ps command is used to show information concerning a selection of the active processes running on a Linux system, you can use it with the grep command to check Apache service uptime as follows.
Here, is the flag:
-e– enables selection of every process on the system.
-o– is used to specify output (comm – command, etime – process execution time, and user – process owner).
# ps -eo comm,etime,user | grep apache2 # ps -eo comm,etime,user | grep root | grep apache2 OR # ps -eo comm,etime,user | grep httpd # ps -eo comm,etime,user | grep root | grep httpd
The sample output below shows that the apache2 service has been running for 4 hours, 10 minutes, and 28 seconds (only consider the one started by root).
Lastly, check out more useful Apache web server guides:
In this article, we showed you three different ways to check Apache/HTTPD service uptime on a Linux system. If you have any questions or thoughts to share, do that via the comment section below.