
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check Apache Server Status and Uptime in Linux
Apache is a popular open-source web server that powers a large percentage of websites on internet. In Linux, Apache can be easily installed and configured to serve web pages and other content. However, it's important to monitor status and uptime of Apache server to ensure it's running smoothly and efficiently. In this article, we'll explore three different ways to check Apache server status and uptime in Linux.
Checking Apache Server Status using systemctl Command
Systemctl is a powerful command-line tool used to manage systemd system and service manager in Linux. It can also be used to check status of Apache web server. Follow steps below to check Apache server status using systemctl command.
Step 1 ? Open a terminal window on your Linux system.
Step 2 ? Type following command to check status of Apache service.
sudo systemctl status apache2
Step 3 ? If Apache server is running, you should see output similar to following.
apache2.service - Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2023-03-13 10:25:21 EDT; 2 days ago Main PID: 1234 (apache2) Tasks: 55 (limit: 9378) Memory: 164.9M CPU: 1min 10.986s CGroup: /system.slice/apache2.service ??1234 /usr/sbin/apache2 -k start ??1235 /usr/sbin/apache2 -k start ??1236 /usr/sbin/apache2 -k start
Step 4 ? If Apache server is not running, you should see output similar to following.
apache2.service - Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: inactive (dead) since Mon 2023-03-13 10:25:21 EDT; 2 days ago Process: 1234 ExecStart=/usr/sbin/apache2 -k start (code=exited, status=0/SUCCESS) Main PID: 1234 (code=exited, status=0/SUCCESS)
In output above, notice that Active status indicates whether Apache server is running or not. If it's running, you'll also see start time, memory usage, and CPU usage of Apache process.
Checking Apache Server Status using apachectl Command
Another way to check status of Apache server is to use apachectl command. This is a command-line tool that comes with Apache web server package. Follow steps below to check status of Apache server using apachectl command.
Step 1 ? Open a terminal window on your Linux system.
Step 2 ? Type following command to check status of Apache service.
sudo apachectl status
Step 3 ? If Apache server is running, you should see output similar to following.
Apache Server Status for localhost (via 127.0.0.1) Server Version: Apache/2.4.46 (Ubuntu) Server MPM: event Server Built: 2021-08-17T18:02:37 Server loaded APR Version: 1.7.0 Compiled with APR Version: 1.7.0 Server loaded APU Version: 1.6.1 Compiled with APU Version: 1.
Step 4 ? If Apache server is not running, you should see output similar to following.
apache2.service - Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: inactive (dead) since Mon 2023-03-13 10:25:21 EDT; 2 days ago Process: 1234 ExecStart=/usr/sbin/apache2 -k start (code=exited, status=0/SUCCESS) Main PID: 1234 (code=exited, status=0/SUCCESS)
In output above, notice that Server Version, Server MPM, and other information about Apache server are displayed. If Apache server is not running, you'll get an error message indicating that server is not running.
Checking Apache Server Uptime using mod_status Module
Apache web server comes with a built-in module called mod_status that can be used to display status of Apache server in real-time. mod_status module displays information such as uptime, total accesses, CPU usage, and other important details about Apache server. Follow steps below to enable and use mod_status module.
Step 1 ? Open a terminal window on your Linux system.
Step 2 ? Type following command to enable mod_status module.
sudo a2enmod status
Step 3 ? Edit Apache configuration file using your favorite text editor.
sudo nano /etc/apache2/mods-enabled/status.conf
Step 4 ? Add following lines to status.conf file to enable access to server status page from localhost.
<Location /server-status> SetHandler server-status Require local </Location>
Step 5 ? Save and close file.
Step 6 ? Restart Apache server.
sudo systemctl restart apache2
Step 7 ? Access server status page using a web browser.
http://localhost/server-status
Step 8 ? If everything is configured correctly, you should see server status page with information about Apache server uptime, total accesses, CPU usage, and other important details.
Apache Server Status for localhost Server Version: Apache/2.4.46 (Ubuntu) Server MPM: event Server Built: 2021-08-17T18:02:37 Server loaded APR Version: 1.7.0 Compiled with APR Version: 1.7.0 Server loaded APU Version: 1.6.1 Compiled with APU Version: 1.6.1 Hostname: localhost Uptime: 2 days 1 hour 2 minutes 17 seconds Restart Time: Monday, 13-Mar-2023 10:25:21 EDT Parent Server Config. Generation: 1 Parent Server MPM Generation: 0 Server uptime: 2 days 1 hour 2 minutes 17 seconds Total accesses: 3462 - Total Traffic: 54.6 MB CPU Usage: u16.55 s14.10 cu0 cs0 - .00716% CPU load 4 requests/sec - 69.9 kB/second - 17.5 kB/request 1 requests currently being processed, 7 idle workers
In output above, notice that Uptime and Server uptime display time since server was last started or restarted. This information is important for monitoring availability and reliability of Apache server.
Additional Tips
You can also use Apache command line utility, apachectl, to check status of server. For example, you can use following command to check status of Apache server.
sudo apachectl status
If you have multiple Apache virtual hosts on your server, you can use ServerName directive in Apache configuration file to specify name of each virtual host. This will help you to differentiate between different virtual hosts in Apache logs and mod_status page.
You can also use a monitoring tool like Nagios, Zabbix, or Cacti to monitor health and performance of your Apache web server. These tools can provide more detailed information about server status, uptime, CPU usage, and other important metrics.
Always keep your Apache server up-to-date with latest security patches and updates to ensure that it is protected from known vulnerabilities and exploits. You can use following command to update Apache server on Ubuntu or Debian-based systems.
sudo apt-get update sudo apt-get upgrade
You can also use a reverse proxy like Nginx or HAProxy to improve performance and scalability of your Apache web server. A reverse proxy can cache static content, load balance incoming requests, and provide SSL termination for HTTPS traffic.
Finally, it's important to regularly backup your Apache web server configuration files, logs, and data to ensure that you can quickly recover from any disasters or data loss. You can use a tool like rsync, scp, or tar to create backups of your Apache server files.
Conclusion
In this article, we explored three different ways to check Apache server status and uptime in Linux. We covered how to use systemctl to check status of Apache server, how to use Apache logs to determine uptime of server, and how to use mod_status module to get real-time information about server status. By following these steps, you can monitor health and performance of your Apache web server to ensure that it is running smoothly.