Solution for Forbidden Icons Directory in Apache

I’m working with a PHP Project that uses an /icons folder for images. The image links were broken on the page and attempting to display the folder contents threw a Forbidden Permissions message.

I’m an /images Man myself, but rather than change the app I wanted to get to the bottom of why using /icons for images was a problem.

I began by opening up terminal to view the directory permissions and everything was as it should be.  Then for kicks I duplicated the /icons folder as /images and the images worked as expected. It had identical perms as the /icons folder so something else was going on.

I was going to http://mysite/icons and knew I didn’t have an index file in the folder, so I added it to no avail.  I also made sure that “Options +Indexes” was set in my .htaccess as well as my apache2 site configuration file.

I went to my site apache2 error log (I configure each site to have its own error log) where I got closer to the problem. The “Directory index forbidden by Options directive” error was pointing to /usr/share/apache2/icons.  “File does not exist” errors when attempting to retrieve individual files confirmed the problem, an icons ALIAS somewhere in Apache2 was tripping me up.

I went to /etc/apache2/apache2.conf where there was no alias for /icons, but apache2.conf loads a lot of mods, including…mod_alias!

There it was, a symbolic link from /etc/apache2/mods-enabled to mods-available, so on to /etc/apache2/mods-available/alias.conf.

And there it is, an alias for /icons to /usr/share/apache2/icons. I don’t use Fancy directory listings, so it was no loss for me to comment out the Alias.

Restarted Apache2 and all was well. The moral to the story being don’t use “/icons” in your PHP apps, and don’t let your friends use it either.