Archive for March 2011

Apache looking for .htaccess in the wrong places – Fixed!

Is Apache looking for a .htaccess file in all the wrong places? Maybe you have an area where one doesn’t even exist, nor should it. Do you get a message such as:

Permission denied: /srv/http/domain/files/images/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable

If you are, you may be wondering why apache is looking for a .htaccess file in the images sub-folder. You may even be wondering why it is asking for one at all because you don’t even use .htaccess file anywhere. Turns out there is a very simple fix.

The problem has to do with file and directory permissions on the server. First off we need to check permissions, here is a fake directory tree for an example.

-rw-r--r--  1 root root    72K 2006-09-30 17:06 file1.htm
drw-r--r--  2 root root   4.0K 2007-05-09 11:52 images/
-rw-r--r--  1 root root    72K 2006-09-30 17:06 index.htm
-rw-r-----  1 root root    625 2010-10-17 14:25 news.php
-rw-------  1 root root    598 2010-10-17 14:25 stuff.php
-rw-r--r--  1 root root     56 2008-03-23 13:42 stuff2.php

See how everything is owned by root? Sometimes this is OK, but for some users it is not possible. Find out from your service provider if you need to use another name, such as apache, or your login user name. For me, I like having everything owned by root. That way other programs or users on my server can’t edit my files.

Look at the images/ directory. It’s permissions are wrong. It turns out Apache wants the directory to be executable. Currently the directory has read-write on user, read on group, and read on world level permissions. We need to make is rwx-r-xr-x, or read-write-execute on user, read-execute on group, and read-execute on world levels.

chmod 755 images/

That should do it. Did you see any other problems with the directory tree above? I actually put 2 more mistakes. They are news.php and stuff.php. Chmod them both to 644. Then they will have the same permissions as index.htm.

If you are like me and want to set the following permissions for everything. I have an easy way of doing it.

-rw-r--r-- for files
drwxr-xr-x for directories
chmod 644 * -R
find . -type d -exec chmod 755 \{\} \;

When complete you will get a list like this.

-rw-r--r--  1 root root    72K 2006-09-30 17:06 file1.htm
drwxr-xr-x  2 root root   4.0K 2007-05-09 11:52 images/
-rw-r--r--  1 root root    72K 2006-09-30 17:06 index.htm
-rw-r--r--  1 root root    625 2010-10-17 14:25 news.php
-rw-r--r--  1 root root    598 2010-10-17 14:25 stuff.php
-rw-r--r--  1 root root     56 2008-03-23 13:42 stuff2.php

That will do it. Keep in mind that depending on your configuration this may not work, but I hope it does. If this did work for you please drop a comment to let others know. Thank you, and good luck!