Verifying the Apache version on your Linux server ensures compatibility with your web applications. Knowing how to check Apache version in Linux is a fundamental skill for system administrators and developers who manage web servers. This guide walks you through multiple methods to find your Apache version, whether you use Apache HTTP Server or Apache Tomcat, on various Linux distributions like Ubuntu, CentOS, or Debian.
Checking your Apache version helps you troubleshoot issues, apply security patches, and confirm that your server runs the correct software for your projects. Let’s dive into the simplest and most reliable commands.
How To Check Apache Version In Linux
The most direct way to check your Apache version is through the command line. Open your terminal and use one of these commands. They work on most Linux distributions.
Using The Apache Binary With The -V Flag
Run this command to see the version and build information:
httpd -v
Or, if your system uses the Apache package name:
apache2 -v
The output looks like:
Server version: Apache/2.4.41 (Ubuntu) Server built: 2023-01-15
This shows the major version (2), minor version (4), and patch level (41). The operating system in parentheses tells you the distribution.
Using The -V Flag For Detailed Information
For more details, use the capital V:
httpd -V
This displays compiled-in modules, server architecture, and configuration file paths. It’s useful for debugging compatibility issues.
Checking Apache Version With Apachectl
The apachectl command also shows the version:
apachectl -v
This works on systems where Apache is controlled by apachectl. If you get a “command not found” error, try the full path or install the Apache utilities.
Alternative Methods For Different Linux Distributions
Sometimes the standard commands don’t work because Apache is installed from a package manager or compiled from source. Here are distribution-specific approaches.
On Ubuntu And Debian Systems
Use the package manager to query the installed version:
dpkg -l | grep apache2
Or check the Apache2 package details:
apt show apache2
This shows the version number along with description and dependencies.
On CentOS, RHEL, And Fedora Systems
For systems using yum or dnf:
rpm -qa | grep httpd
Or:
yum info httpd
On newer Fedora versions, use:
dnf info httpd
These commands display the exact version from the repository.
On OpenSUSE Systems
Use zypper:
zypper info apache2
Or check the installed package:
rpm -q apache2
Checking Apache Version From Configuration Files
If you can’t run commands, check the Apache configuration files. The version is often written in the main config file or error log.
Viewing The Error Log
Apache logs its version on startup. Check the error log:
cat /var/log/apache2/error.log | head -10
On CentOS, the log is at /var/log/httpd/error_log. Look for a line like:
[Mon Jan 15 10:00:00.123456 2023] [core:notice] [pid 1234] AH00094: Command line: '/usr/sbin/apache2'
This line often includes the version number.
Checking The Binary File Itself
Use the strings command to extract version info from the Apache binary:
strings /usr/sbin/apache2 | grep -i version
This works even if the binary is renamed or moved.
Using PHP Or Server Status To Check Apache Version
If you have a web server running, you can check the version through a browser or PHP script.
Creating A PHP Info File
Create a file called info.php in your web root (e.g., /var/www/html/):
<?php phpinfo(); ?>
Access it via http://your-server-ip/info.php. Look for the “Server API” or “Apache Version” section. This method also shows loaded modules.
Checking Server Headers
Use curl to view HTTP response headers:
curl -I http://localhost
The Server header often includes the Apache version:
Server: Apache/2.4.41 (Ubuntu)
Note: Some administrators hide the version for security reasons, so this may not always work.
How To Check Apache Version In Linux For Apache Tomcat
Apache Tomcat is a separate Java-based server. To check its version:
Using The Catalina.sh Script
/usr/share/tomcat/bin/catalina.sh version
Or if Tomcat is installed via package:
rpm -qa | grep tomcat
On Ubuntu:
dpkg -l | grep tomcat
Checking The Server Info Page
Access http://your-server:8080 and look for the version in the footer. Tomcat displays it by default.
Troubleshooting Common Issues
Sometimes you get errors when trying to check the version. Here are fixes.
Command Not Found Error
If httpd or apache2 isn’t found, Apache may not be installed or the path isn’t in your $PATH. Try:
which httpd apache2
Or search for the binary:
find / -name httpd -o -name apache2 2>/dev/null
If nothing appears, install Apache with your package manager:
sudo apt install apache2 (Ubuntu) or sudo yum install httpd (CentOS).
Permission Denied Errors
Some commands require root privileges. Use sudo:
sudo httpd -v
This is common when checking logs or binary files.
Apache Is Running But Commands Fail
If Apache is running but commands return nothing, it might be a containerized installation. Check inside Docker containers:
docker exec container_name httpd -v
Why Checking Apache Version Matters
Knowing your Apache version helps with security, compatibility, and performance. Here are key reasons.
- Security patches: Older versions have known vulnerabilities. Check regularly to apply updates.
- Module compatibility: Some modules require specific Apache versions. Verify before upgrading.
- Configuration syntax: Newer versions deprecate old directives. Check version to avoid errors.
- Performance tuning: Different versions have different default settings. Adjust accordingly.
Automating Version Checks With Scripts
For multiple servers, automate the version check with a bash script.
Simple Version Check Script
#!/bin/bash
# Check Apache version on remote servers
for server in server1 server2 server3; do
echo "Checking $server..."
ssh user@$server "httpd -v 2>/dev/null || apache2 -v"
done
Save this as check_apache.sh and run it. It works for both httpd and apache2 binaries.
Using Ansible Or Puppet
Configuration management tools can check versions across your infrastructure. Example Ansible task:
- name: Check Apache version command: httpd -v register: apache_version - debug: var=apache_version.stdout
Frequently Asked Questions
Here are common questions about checking Apache version in Linux.
How can I check Apache version without root access?
Use the phpinfo() method or check server headers with curl. These don’t require root.
What’s the difference between httpd and apache2?
httpd is the traditional name on Red Hat-based systems (CentOS, Fedora). apache2 is used on Debian-based systems (Ubuntu, Debian). Both are the same Apache server.
Can I check Apache version from a web browser?
Yes, if the Server header isn’t hidden. Use curl -I or view the server status page if enabled.
Why does my Apache version show as “Apache/2.4.41 (Ubuntu)”?
The parentheses indicate the operating system or distribution where Apache was compiled. It helps identify package-specific patches.
How often should I check my Apache version?
Check after updates, before deploying new applications, and monthly for security audits. Automate it if you manage many servers.
Conclusion
Knowing how to check Apache version in Linux is a simple but essential skill. Use the httpd -v or apache2 -v command for a quick answer. For more details, try the -V flag or check configuration files. Remember to adapt commands to your distribution—Ubuntu uses apache2, CentOS uses httpd. Automate checks for multiple servers to stay on top of updates and security. Now you can confidently verify your Apache version and ensure your web server runs smoothly.