Verifying your web server is operational starts with knowing how to check if Apache is running on Linux. This is a fundamental task for any system administrator or developer managing web services. Whether you are troubleshooting a down site or confirming a fresh installation, these methods will give you a clear answer quickly.
Apache is one of the most popular web servers on the internet. It powers millions of websites. But like any service, it can stop unexpectedly. Knowing how to check its status saves you time and frustration. Below, we cover every practical way to verify Apache’s state on a Linux system.
How To Check If Apache Is Running On Linux
There are multiple ways to check Apache’s status. Each method works on different Linux distributions. Some use systemd, others use init.d, and some rely on direct process inspection. We will walk through all of them step by step.
Using Systemctl With Systemd Distributions
Most modern Linux distributions use systemd. This includes Ubuntu 16.04+, CentOS 7+, Debian 8+, and Fedora. The systemctl command is your primary tool here.
- Open a terminal window.
- Run this command:
sudo systemctl status apache2(on Debian/Ubuntu) orsudo systemctl status httpd(on RHEL/CentOS/Fedora). - Look for the line that says “Active: active (running)” in green. If it says “inactive (dead)” or “failed”, Apache is not running.
You can also check if the service is enabled to start on boot. Use sudo systemctl is-enabled apache2. This tells you if Apache will start automatically after a reboot.
Using Service Command For Older Systems
Some older Linux versions or minimal installations still use SysV init. The service command works here. It is simpler but gives less detail.
- For Debian/Ubuntu:
sudo service apache2 status - For RHEL/CentOS 6 or older:
sudo service httpd status
If Apache is running, you will see a message like “apache2 is running.” If not, it will say “apache2 is not running.” This method is straightforward but does not show process details.
Checking Apache Process Directly With Ps
Sometimes you want to see the actual processes. The ps command lists all running processes. You can filter for Apache specifically.
Run: ps aux | grep apache or ps aux | grep httpd
If Apache is running, you will see multiple lines. The first line usually shows the parent process owned by root. The child processes run as the www-data or apache user. If you see no output except the grep line itself, Apache is not running.
For a cleaner view, use: pgrep -x apache2 or pgrep -x httpd. This returns only process IDs. A numeric output means Apache is active. No output means it is stopped.
Checking Apache Port Status With Netstat Or Ss
Apache listens on port 80 (HTTP) and sometimes port 443 (HTTPS). Checking if these ports are open tells you if the server is accepting connections.
Use netstat: sudo netstat -tulpn | grep :80
Or use the modern ss command: sudo ss -tulpn | grep :80
If you see a line with “LISTEN” and the process name “apache2” or “httpd”, Apache is running. The output shows the IP address and port. For example: “tcp LISTEN 0 128 0.0.0.0:80 0.0.0.0:* users:((“apache2″,pid=1234))”
This method is especially useful when Apache is running but not responding properly. The port might be open even if the service is misconfigured.
Using Curl Or Wget To Test Apache Locally
A practical test is to request a page from Apache locally. This confirms the server is not only running but also serving content.
Run: curl -I http://localhost or wget --spider http://localhost
A successful response shows “HTTP/1.1 200 OK” or similar. If you get “Connection refused” or “No route to host”, Apache is likely not running or blocked by a firewall.
You can also check the default Apache page: curl http://localhost. If you see HTML content with “It works!” or your custom site, Apache is operational.
Checking Apache Logs For Clues
Logs tell the full story. Even if Apache appears to be running, errors might prevent it from serving pages. The main log files are:
- Access log:
/var/log/apache2/access.log(Debian/Ubuntu) or/var/log/httpd/access_log(RHEL/CentOS) - Error log:
/var/log/apache2/error.logor/var/log/httpd/error_log
Use tail to see recent entries: sudo tail -f /var/log/apache2/error.log
Look for lines like “AH00015: Child process started” or “Resuming normal operations”. Errors like “Address already in use” or “No listening sockets available” indicate problems.
Using Htop Or Top For Real-Time Monitoring
If you want a visual overview, use htop or top. These tools show all processes in real time.
Install htop if needed: sudo apt install htop or sudo yum install htop
Run htop and press F4 to search. Type “apache” or “httpd”. You will see all Apache processes. The CPU and memory usage per process is displayed. This helps identify if Apache is consuming too many resources.
Checking Apache Configuration Syntax
A common reason Apache stops is a configuration error. After making changes, always test the syntax before restarting.
Run: sudo apachectl configtest or sudo apache2ctl configtest
If the syntax is OK, you see “Syntax OK”. If there are errors, Apache will not start. The output tells you the exact line and file with the problem.
This is not a direct check for running status, but it prevents future downtime. Always run this after editing config files.
Automating Apache Status Checks With Scripts
You can write a simple bash script to check Apache automatically. This is useful for monitoring multiple servers.
#!/bin/bash
if systemctl is-active --quiet apache2; then
echo "Apache is running"
else
echo "Apache is not running"
# Optionally restart: sudo systemctl restart apache2
fi
Save this as check_apache.sh and make it executable with chmod +x check_apache.sh. Run it with cron for periodic checks.
Common Issues When Apache Is Not Running
If your checks show Apache is stopped, here are typical causes:
- Port conflict: Another service (like nginx or a Java app) is using port 80 or 443.
- Out of memory: The system ran out of RAM and the OOM killer stopped Apache.
- Configuration error: A recent edit to httpd.conf or a .htaccess file has a typo.
- Firewall blocking: iptables or firewalld might block incoming connections even if Apache is running.
- SSL certificate expired: If Apache uses HTTPS, an expired cert can prevent startup.
Check the error log first. It usually points directly to the problem.
How To Restart Apache If It Is Not Running
Once you confirm Apache is down, restart it with the appropriate command.
- Systemd:
sudo systemctl restart apache2orsudo systemctl restart httpd - SysV init:
sudo service apache2 restartorsudo service httpd restart
After restarting, run the status check again. Also test with curl to ensure pages load.
Checking Apache On Docker Containers
If Apache runs inside a Docker container, the checks are slightly different. First, find the container ID or name.
Run: docker ps | grep apache
Then check the container’s process: docker exec <container_name> ps aux | grep apache
Or check the container’s logs: docker logs <container_name>
You can also use docker stats to see resource usage in real time.
Using Nmap To Check Apache From Another Machine
Sometimes you need to verify Apache is accessible from the network. Nmap is a powerful network scanner.
Run: nmap -p 80 <server_ip>
If port 80 shows “open”, Apache is listening. If it shows “filtered”, a firewall might be blocking access. If “closed”, Apache is not running on that port.
This is useful for remote troubleshooting. Just ensure you have permission to scan the target server.
Checking Apache Version For Compatibility
Knowing the Apache version helps with debugging. Use one of these commands:
apache2 -vorhttpd -vdpkg -l | grep apache(Debian/Ubuntu)rpm -qa | grep httpd(RHEL/CentOS)
This shows the version number and build date. Some features or security patches depend on the version.
Monitoring Apache With Third-Party Tools
For production servers, consider using monitoring tools. They alert you when Apache stops.
- Nagios: Can check Apache status via plugins.
- Zabbix: Monitors Apache process and port availability.
- Prometheus with Apache exporter: Collects metrics like requests per second.
- Simple bash scripts with cron: Send email alerts on failure.
These tools reduce manual checks. They are essential for high-availability environments.
Frequently Asked Questions
Q: How do I check if Apache is running on Linux without sudo?
You can use ps aux | grep apache or pgrep apache2 without root. However, some process details may be hidden. Port checks with netstat usually require sudo.
Q: What is the difference between apache2 and httpd?
Apache2 is the package name on Debian-based systems. Httpd is used on RHEL-based systems. They are the same software, just different naming conventions.
Q: Why does my Apache status show “active (exited)”?
This usually means Apache started but then stopped immediately. Check the error log for configuration errors or port conflicts. The service may have exited due to a fatal error.
Q: Can I check Apache status remotely?
Yes, use curl from another machine: curl -I http://your-server-ip. Or use nmap to scan the port. Remote checks require network access and firewall rules allowing the connection.
Q: How often should I check Apache status?
For critical servers, set up automated monitoring every 1-5 minutes. Manual checks are fine for development. Use cron scripts or monitoring tools for production.
Knowing how to check if Apache is running on Linux is a core skill. You now have multiple methods at your disposal. Start with systemctl for modern systems. Use ps for a quick process view. Test with curl for actual functionality. And always check the logs when something seems off. With these techniques, you can quickly diagnose and resolve Apache issues.
Remember to test after any configuration change. A simple syntax check can save hours of troubleshooting. Automate your checks where possible. This keeps your web server reliable and your sites accessible.
Now you have a complete toolkit. Go ahead and verify your Apache server’s status with confidence.