This guide offers essential troubleshooting steps for Apache webserver issues.
1. Check Apache Status:
Ensure Apache is running by checking its status:
Debian/Ubuntu: sudo systemctl status apache2
CentOS: systemctl status httpd
If it's not running, restart Apache:
Debian/Ubuntu: sudo service apache2 restart
CentOS: sudo service httpd restart
2. Reload Apache:
To apply configuration changes without downtime, reload Apache:
- Debian/Ubuntu:
/etc/init.d/apache2 reload
- CentOS:
/etc/init.d/httpd reload
3. Check Apache Logs:
View error logs live using tail -f
, or inspect them with cat
:
Debian/Ubuntu: /var/log/apache2/error.log
CentOS: /var/log/httpd/error_log
Access logs, which provide visitor data, can be found here:
Debian/Ubuntu: /var/log/apache2/access.log
CentOS: /var/log/httpd/access_log
4. Apache Configuration Syntax:
Check configuration file syntax for errors:
- Debian/Ubuntu:
apache2ctl -t
- CentOS:
httpd -t
5. Virtual Host Definitions:
There is an Apache command that allows you to view all virtual hosts configured on the server, along with their options, file names, and the line numbers where they are defined.
This command helps you identify all domains configured on the server and locate the correct configuration file for updating domain-specific settings.
To list all virtual hosts:
Debian/Ubuntu:
apache2ctl -S
CentOS:
httpd -S
Explanation of the Output:
The output shows all virtual hosts, along with the IP addresses and port numbers they use. These should match the addresses and ports specified in the NameVirtualHost directives.
For instance, if you’ve set NameVirtualHosts *:80, the virtual host configuration should start with that IP and port combination. This helps in verifying that your virtual hosts are correctly configured with the appropriate directives.
This command helps identify domain configurations and locate files for updating settings.
6. Conflicting Directives:
If changes to a configuration option aren’t reflected after reloading the server, it’s possible that a conflicting directive is overriding the new settings. The key point is that newer directives take precedence over older ones. Therefore, the most recently read directive will be the one that takes effect.
Key Points on How Directives are Read:
- Included Files: Files included in the configuration are read at the point they are included, before the rest of the original file.
- Directory Inclusion: When an entire directory is included, the files are read alphabetically by name.
- Ports Configuration: On Debian and Ubuntu,
/etc/apache2/ports.conf
contains NameVirtualHost
and Listen
directives that determine the IP addresses and ports Apache binds to. These can sometimes conflict with settings in other files.
- Directory and .htaccess Files: Directory settings are read when the server starts or reloads, but
.htaccess
files are read before serving resources. .htaccess
files can override directory configurations, so for testing, temporarily disable them.
If issues persist, a deeper investigation of the VPS may be needed, and consultation with a VPS administrator might be necessary.
For more details, consult the official Apache web server documentation.