Found out the hard way today that there’ve been SIGNIFICANT changes in configuration syntax and requirements since Apache 2.2, when I tried to set up a VERY simple couple of vhosts on Apache 2.4.7 on a brand new Ubuntu Trusty Tahr install.
First – the a2ensite/a2dissite scripts refuse to work unless your vhost config files end in .conf. BE WARNED. Example:
you@trusty:~$ ls /etc/apache2/sites-available 000-default.conf default-ssl.conf testsite.tld you@trusty:~$ sudo a2ensite testsite.tld ERROR: Site testsite.tld does not exist!
The solution is a little annoying; you MUST end the filename of your vhost configs in .conf – after that, a2ensite and a2dissite work as you’d expect.
you@trusty:~$ sudo mv /etc/apache2/sites-available/testsite.tld /etc/apache2/sites-available/testsite.tld.conf you@trusty:~$ sudo a2ensite testsite.tld Enabling site testsite.tld To activate the new configuration, you need to run: service apache2 reload
After that, I had a more serious problem. The “site” I was trying to enable was nothing other than a simple exposure of a directory (a local ubuntu mirror I had set up) – no php, no cgi, nothing fancy at all. Here was my vhost config file:
<VirtualHost *:80> ServerName us.archive.ubuntu.com ServerAlias us.archive.ubuntu.local Options Includes FollowSymLinks MultiViews Indexes DocumentRoot /data/apt-mirror/mirror/us.archive.ubuntu.com *lt;Directory /data/apt-mirror/mirror/us.archive.ubuntu.com/> Options Indexes FollowSymLinks AllowOverride None </Directory> </VirtualHost>
Can’t get much simpler, right? This would have worked fine in any previous version of Apache, but not in Apache 2.4.7, the version supplied with Trusty Tahr 14.04 LTS.
Every attempt to browse the directory gave me a 403 Forbidden error, which confused me to no end, since the directories were chmod 755 and chgrp www-data. Checking Apache’s error log gave me pages on pages of lines like this:
[Mon Jun 02 10:45:19.948537 2014] [authz_core:error] [pid 27287:tid 140152894646016] [client 127.0.0.1:40921] AH01630: client denied by server configuration: /data/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/
What I eventually discovered was that since 2.4, Apache not only requires explicit authentication setup and permission for every directory to be browsed, the syntax has changed as well. The old “Order Deny, Allow” and “Allow from all” won’t cut it – you now need “Require all granted”. Here is my final working vhost .conf file:
<VirtualHost *:80> ServerName us.archive.ubuntu.com ServerAlias us.archive.ubuntu.local Options Includes FollowSymLinks MultiViews Indexes DocumentRoot /data/apt-mirror/mirror/us.archive.ubuntu.com <Directory /data/apt-mirror/mirror/us.archive.ubuntu.com/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost>
Hope this helps someone else – this was a frustrating start to the morning for me.
thanks! this solved my problem
For me the weird thing is that this problem happens only in the virtual host for production, while my staging virtual host does not fail.