Directory listings in Apache 2.4
Yosemite updates Apache to 2.4. A couple of things stopped working from my previous installation, including autogenerated directory listings. Here's how I got them back.
Yosemite updates Apache from 2.2 to 2.4
It copies the old httpd.conf to
/etc/apache2/httpd.conf~previous and replaces it with a vannilla one. Annoying, but not too painful to replace, and it doesn't touch the vhosts. The list of 2.4 changes doesn't include anything I actually use. Sadly that doesn't mean nothing important has changed - rather, they didn't bother to list things that matter to me.
Apache "directory listing forbidden"
I used to rely on the automatic directory listings generated by mod_autoidex, but they has stopped working. The logs give the message
No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive. "Impossible!" I cry, the settings are right, and they always worked.
This is the DocumentRoot fragment of httpd.conf.
+Indexes is the bit which is supposed to turn on auto-indexing. I use /Library/... for not so important documents I need to put under a webserver for whatever reason.
DocumentRoot "/Library/WebServer/Documents" <Directory "/Library/WebServer/Documents"> Options +Indexes +FollowSymLinks # etc </Directory>
And this is one of the virtual hosts. For serious dev work, I put my vhosts somewhere other than /Library/...
<VirtualHost *:81> DocumentRoot "/pth/to/somewhere/completely/different" ServerName my-virtual-host.dev ErrorLog "/private/var/log/apache2/my-virtual-host.dev-error_log" CustomLog "/private/var/log/apache2/my-virtual-host.dev-access_log" common </VirtualHost>
What has changed is that now the options for DocumentRoot don't automatically carry over to folders which are not subdirectories of DocumentRoot. This can be easily fixed by changing virtual hosts to
<VirtualHost *:80> DocumentRoot "/pth/to/somewhere/completely/different" ServerName my-virtual-host.dev ErrorLog "/private/var/log/apache2/my-virtual-host.dev-error_log" CustomLog "/private/var/log/apache2/my-virtual-host.dev-access_log" common <Directory "/pth/to/somewhere/completely/different"> Options +Indexes </Directory> </VirtualHost>
That proves what the problem is, but it sucks having to do that for every virtual host. The solution is to add the directive for the common parent folder of all my virtual hosts in httpd.conf
<Directory "/parent/of/somewhere/completely/different"> Options +Indexes </Directory>
Restart apache and all is well
sudo apachectl restart everything works fine.