4 Ways To Check Uptime of Apache Web Server (httpd) on Linux

We all know about the purpose of uptime command in Linux.

It is used to check the uptime of the Linux system, how long the system has been running without restarting.

If you want to check other service uptime like Apache, MySQL, sftp, etc. on Linux, how do you do that?

Each service has their own command to check the service uptime.

Also, we can check the service uptime using the ps command because there are many options to collect this information.

It shows when the parent process started (which I say when it restarts or starts) and how long the service runs with the [DD:HH:MM:SS] format.

In this tutorial, we are going to show you how to check Apache web server uptime using different method.

This is a small tutorial and very useful if you want to get Apache web server uptime for some reason.

This can be done using the following 4 methods.

  • Apache mod_status module
  • ps command
  • systemctl command
  • proc filesystem (procfs)

Method-1: How to Check Apache (httpd) Web Server Uptime Using mod_status Module on Linux

The Apache mode_status module allows a server administrator to check Apache Web server uptime, concurrent connections, and server performance with a given interval through the CLI and GUI.

However, it is disabled by default and must be enabled to use the feature.

The Apache “mod_status” module displays the following useful information about the Apache Web server.

  • Apache Web server built & version information
  • Web server last restart & uptime information
  • Total number of incoming requests
  • Idle workers
  • Server load & Web server CPU usage
  • Total traffic (Bandwidth usage)
  • Average number of requests per second
  • Average number of bytes per request
  • Number of bytes served per second
  • How many requests currently being processed
  • Details about running process

How to Install and Enable Apache’s mod_status Module on Linux

By default, the Apache “mod_status” module is installed on Apache. But reports are disabled and you have to uncomment it to access it. To do so, you need to uncomment the codes below in your Apache configuration file based on your distribution.

See the following article if you want to verify the Apache web server performance using the mod_status module.

For RHEL/CentOS/Fedora systems, open the /etc/httpd/conf/httpd.conf file and uncomment the below codes.

[For Apache 2.2]
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from all
</Location>

[For Apache 2.4]
<Location "/server-status">
    SetHandler server-status
    Require host localhost
</Location>

For Debian/Ubuntu systems, open /etc/apache2/mods-enabled/status.conf file and uncomment the below codes.

<Location "/server-status">
    SetHandler server-status
    Require local
    #Require ip 192.0.2.024
</Location>

Save and close the file and restart the Apache web server service.

Use the below commands to restart the Apache (httpd) server in Linux.

For SysVinit Systems – openSUSE & Debian based systems.

# service apache2 restart
or
# /etc/init.d/apache2 restart

For SysVinit Systems – RHEL (RedHat) based systems.

# service httpd restart
or
# /etc/init.d/httpd restart

For systemd Systems – openSUSE & Debian based systems.

# systemctl restart apache2.service
or
# systemctl restart apache2

For systemd Systems – RHEL (RedHat) based systems.

# systemctl restart httpd
or
# systemctl restart httpd.service

Run the following command to get the Apache uptime.

$ apachectl status
               Apache Server Status for localhost (via 127.0.0.1)

   Server Version: Apache/2.4.29 (Ubuntu)

   Server MPM: prefork

   Server Built: 2019-09-16T12:58:48

   --------------------------------------------------------------------------

   Current Time: Wednesday, 27-Nov-2019 13:06:03 IST

   Restart Time: Wednesday, 27-Nov-2019 12:24:26 IST

   Parent Server Config. Generation: 2

   Parent Server MPM Generation: 1

   Server uptime: 41 minutes 36 seconds

   Server load: 0.00 0.02 0.14

   Total accesses: 8 - Total Traffic: 88 kB

   CPU Usage: u0 s0 cu0 cs0

   .00321 requests/sec - 36 B/second - 11.0 kB/request

   1 requests currently being processed, 4 idle workers

 __W__...........................................................
 ................................................................
 ......................

   Scoreboard Key:
   "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
   "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
   "C" Closing connection, "L" Logging, "G" Gracefully finishing,
   "I" Idle cleanup of worker, "." Open slot with no current process

Alternatively, you can run this command using a Linux text-based browser.

$ elinks http://localhost/server-status

Apache uptime with page refresh every N seconds.

$ elinks http://localhost/server-status?refresh=5

Method-2: How to Check Apache (httpd) Web Server Uptime Using the ps Command on Linux

The ps command displays information about a selection of the active processes. It displays the process ID (pid=PID), the terminal associated with the process (tname=TTY), the cumulated CPU time in [DD-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD). Output is unsorted by default.

To do so, you need to find the PID of the Apache process, and it can be easily identified using the pidof command.

For RPM based systems:

# pgrep httpd | head -1
10915

For DEB based systems:

# pgrep apache2 | head -1
1111

Once you get the Apache PID, use the following command to get it.

# ps -p 10915 -o etime
    ELAPSED
   05:59:59

The above output shows the elapsed time since the process was started. As per the above output, it’s up and running 5 hours, 59 mins, and 59 sec.

Method-3: How to Check Apache (httpd) Web Server Uptime Using the systemctl Command on Linux

The systemctl command is used to control the systemd service manager. This is a replacement for the old SysVinit system management, and most of the modern Linux operating systems have been moved to the systemd.

# systemctl status httpd

● httpd.service - Web server Apache
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-11-27 03:43:37 UTC; 5h 50min ago
  Process: 10907 ExecStop=/usr/local/apache/bin/apachectl graceful-stop (code=exited, status=0/SUCCESS)
  Process: 11025 ExecReload=/usr/local/apache/bin/apachectl graceful (code=exited, status=0/SUCCESS)
  Process: 10912 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 10915 (httpd)
   CGroup: /system.slice/httpd.service
           ├─10915 /usr/local/apache/bin/httpd -k start
           ├─11082 /usr/local/apache/bin/httpd -k start
           ├─11083 /usr/local/apache/bin/httpd -k start
           ├─11084 /usr/local/apache/bin/httpd -k start
           └─11681 /usr/local/apache/bin/httpd -k start

Nov 27 03:43:37 ns1.nsforcdn.com systemd[1]: Started Web server Apache.
Nov 27 03:43:38 ns1.nsforcdn.com systemd[1]: Reloading Web server Apache.
Nov 27 03:43:38 ns1.nsforcdn.com apachectl[11025]: AH00112: Warning: DocumentRoot [/home/nowdigitaleasy/public_html/billing] does not exist
Nov 27 03:43:38 ns1.nsforcdn.com apachectl[11025]: AH00112: Warning: DocumentRoot [/home/nowdigitaleasy/public_html/billing] does not exist
Nov 27 03:43:38 ns1.nsforcdn.com apachectl[11025]: AH00112: Warning: DocumentRoot [/home/nutechnologyinc/public_html/poc.nutechnologyinc.com] does not exist
Nov 27 03:43:38 ns1.nsforcdn.com apachectl[11025]: AH00112: Warning: DocumentRoot [/home/witskills/public_html] does not exist
Nov 27 03:43:38 ns1.nsforcdn.com apachectl[11025]: AH00112: Warning: DocumentRoot [/home/witskills/public_html] does not exist
Nov 27 03:43:38 ns1.nsforcdn.com systemd[1]: Reloaded Web server Apache.
Hint: Some lines were ellipsized, use -l to show in full.

Method-4: How to Check Apache (httpd) Web Server Uptime Using the proc filesystem (procfs) on Linux

The proc filesystem (procfs) is a special filesystem in Unix-like operating systems that presents information about processes and other system information.

It’s sometimes referred to as a process information pseudo-file system. It doesn’t contain ‘real’ files but run time system information (e.g. system memory, devices mounted, hardware configuration, etc).

Once you have Apache PID, use the following proc file system to identify it. As per the below output the httpd process has been running since Aug 05 at 17:20.

# ls -ld /proc/10915

dr-xr-xr-x. 9 root root 0 Aug  5 17:20 /proc/10915/

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...