28

Today i migrated my images from one server to another and faced a strange permission issue

[Mon Mar 25 08:42:23.676315 2013] [core:crit] [pid 15182] (13)Permission denied: [client 24.14.2.22:48113] AH00529: /files/domain.com/public_html/images/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/files/domain.com/public_html/images/' is executable, referer: http://domain.com.com/file.php

what i've tried:

    chmod -R 777 root_dir
    restorecon -r
    disable selinux
    Chown -R root:root root_dir
3
  • 2
    that was a bug in aufs, some disks had wrong permissions.
    – teslasimus
    Commented Mar 25, 2013 at 4:10
  • 6
    you need all of the parent directories are readable from the web server's user, in addition to the root directory itself.
    – Chuan Ma
    Commented Mar 25, 2013 at 11:04
  • chmod -R 777 is a very dangerous thing to do. It makes every directory and file world writable and executable. If you want to make every file underneath root_dir world readable and every dir under root_dir world executable (so everyone, including the web server, can access a file if the name is known), a safer alternative would be find root_dir -type f -print0|xargs -0 chmod o+r; find root_dir -type d -print0|xargs -0 chmod o+x Substitute o+rx if you want the world to be able to do an ls or readdir on every directory.
    – BertD
    Commented Jul 8, 2015 at 22:29

7 Answers 7

32

Today I faced this problem. I transferred public_html from the old drive to new one and chown like this:

chown -R owner:owner public_html

This is correct for sub directories and files inside public_html, but the user of public_html must be nobody so apache can check it's content, so this solved my problem:

chown owner:nobody public_html

Note: owner is the user (for example web1)

4
  • 9
    The situation is similar in Plesk: /var/www/vhosts/example.com folder must be owned by user:psaserv, but everything in it by user:psacln. Commented Nov 27, 2013 at 14:52
  • 1
    links to documentation? This doesn't seem quite right. Commented Jul 21, 2019 at 13:57
  • Wouldn't this make it so that only root can modify the folder? Commented Feb 4, 2020 at 17:06
  • Halil Özgür your suggestion about Plesk saved my day after moving all files and folders from httpsdocs to httpdocs (and switching of compatibility in the relevant Plesk Obsidian account).
    – Klaaz
    Commented Jan 6, 2021 at 11:18
22

I had the same problem. For me, it's a problem of SeLinux (CentOS 7).

It works for me:

$ setsebool -P httpd_enable_homedirs true
$ chcon -R -t httpd_sys_content_t /var/www/html/

Note that you should change the above /var/www/html/ to an appropriate directory.

1
  • 1
    This helped me a lot getting Laravel working on CentOS 7 (LAMP). Thank you so much.
    – Pathros
    Commented Oct 25, 2018 at 5:14
3

I was using Plesk onyx and I got the same error message, I just changed the folder permission to 775 and it worked for me.

3

Other way is

sudo setenforce 0

Disable SELinux

I hope this works for you

1
  • This is an unsecure TEMPORAY WORKAROUND only. After a reboot, the change is gone. Also, it is not a good solution to just turn off security. Better find the real problem and fix it properly. IF you give such an answer, please point out these caveats and if it is a workaround or a solution. Commented Aug 30, 2023 at 7:50
1

TL;DR:

sudo chmod a+rx /var{,/services{,/web{,/web-folder}}};
find /var/services/web/web-folder -type d -exec sudo chmod a+rx {} +;

You need to make certain that the directory, and all of its parent directories, are readable and executable (executability is required to open a directory) by the web server. You can do this by making the web server user the owner and making the user perms (EG: chown apache <dir>; chmod u+rx <dir>;), or by a making the group be the web server group a group which includes the web server user and setting the group perms to (EG: chgrp apache <dir>; chmod g+rx <dir>;), or by setting the world perms to (EG: chmod o+rx <dir>;).

1
  • 1
    running chmod a+x on the root site folder worked for me on OS X
    – Anthony
    Commented Jun 28, 2015 at 21:19
0

open your httpd.conf file and change Deny from all to Allow from all on the .htaccess file

The following lines prevent .htaccess and .htpasswd files from being

viewed by Web clients.

<FileMatch "^\.ht">
  Order allow,dey
  Allow from all
</FileMatch>

this solved my problem

3
  • Thanks a lot! However it's deny not dey.
    – Revadike
    Commented Oct 15, 2021 at 13:36
  • Is it really necessary to use bold huge text in this answer? Commented Aug 30, 2023 at 7:33
  • Also, this answer is misleading and wrong. It is not necessary to allow access to .htaccess via the web. In fact, it SHOULD be disallowed. Commented Aug 30, 2023 at 7:34
-1

When I checked httpd/user-error_log, it gave

[Fri Jan 09 18:58:08 2015] [crit] [client 192.168.1.xxx] (13)Permission
denied: /var/services/web/web-folder/.htaccess pcfg_openfile: unable to check
htaccess file, ensure it is readable

chmod 755 is not fixing the problem. Below command is what works for me. I use http since it is the apache user and group used in Synology DSM 5.1-5021

  cd /var/services/web
  chown http:http web-folder


 apache httpd.conf @ /etc/httpd/conf/httpd.conf

more details about the new change Apache / Webserver limitations in 5.0

1
  • I didn't get it. Could you please add more details?
    – Pathros
    Commented Oct 25, 2018 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.