Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug an apache virtual host configuration?

People also ask

How do I put Apache in debug mode?

If apache fails to start and the configuration check option reports a valid configuration file, the apache debug log level can be used to have apache log additional data to the error_log. To enable the debug log level, the “LogLevel” directive can be set to “debug” in the apache configuration file.

Where is the virtual host configuration file in Apache?

Creating a Virtual Hosts On Ubuntu systems, Apache Virtual Hosts configuration files are located in /etc/apache2/sites-available directory. They can be enabled by creating symbolic links to the /etc/apache2/sites-enabled directory, which Apache read during the startup.

How do I find virtual hosts?

The command apache2ctl -S check site-enabled*. conf + httpd. conf files and show you if the syntax is correct and the list of virtual host (and some more informations). But It doesn't check if virtualhosts are running, you can try to stop your Apache and launch again the command, the result will be the same.


Syntax check

To check configuration files for syntax errors:

# Red Hat-based (Fedora, CentOS), Arch-based and OSX
httpd -t

# Debian-based (Ubuntu)
apache2ctl -t

# MacOS
apachectl -t

List virtual hosts

To list all virtual hosts, and their locations:

# Red Hat-based (Fedora, CentOS), Arch-based and OSX
httpd -S

# Debian-based (Ubuntu)
apache2ctl -S

# MacOS
apachectl -S

Here's a command I think could be of some help :

apachectl -t -D DUMP_VHOSTS

You'll get a list of all the vhosts, you'll know which one is the default one and you'll make sure that your syntax is correct (same as apachectl configtest suggested by yojimbo87).

You'll also know where each vhost is declared. It can be handy if your config files are a mess. ;)


If you are trying to debug your virtual host configuration, you may find the Apache -S command line switch useful. That is, type the following command:

httpd -S

This command will dump out a description of how Apache parsed the configuration file. Careful examination of the IP addresses and server names may help uncover configuration mistakes. (See the docs for the httpd program for other command line options).


First check out config files for syntax errors with apachectl configtest and then look into apache error logs.


I had a new VirtualHost configuration file that was not showing when using the apachectl -S command. After much head scratching I realised that my file did not have suffix ".conf". Once I renamed the file with that suffix my Vhost started showing and working!


I recently had some issues with a VirtualHost. I used a2ensite to enable a host but before running a restart (which would kill the server on fail) I ran

apache2ctl -S

Which gives you some info about what's going on with your virtual hosts. It's not perfect, but it helps.