Permission denied: /var/www/abc/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable?

150,194

Solution 1

Make sure that the htaccess file is readable by apache:

chmod 644 /var/www/abc/.htaccess 

And make sure the directory it's in is readable and executable:

chmod 755 /var/www/abc/

Solution 2

I had the same issue when I changed the home directory of one use. In my case it was because of selinux. I used the below to fix the issue:

selinuxenabled 0
setenforce 0

Solution 3

If it gets into the selinux arena you've got a much more complicated issue. It's not a good idea to remove the selinux protection but to embrace it and use the tools that were designed to manage it.

If you are serving content out of /var/www/abc, you can verify the selinux permissions with a Z appended to the normal ls -l command. i.e. ls -laZ will give the selinux context.

To add a directory to be served by selinux you can use the semanage command like this. This will change the label on /var/www/abc to httpd_sys_content_t

semanage fcontext -a -t httpd_sys_content_t /var/www/abc

this will update the label for /var/www/abc

restorecon /var/www/abc 

This answer was taken from unixmen and modified to fit this question. I had been searching for this answer for a while and finally found it so felt like I needed to share somewhere. Hope it helps someone.

Share:
150,194
PHPLover
Author by

PHPLover

Updated on July 09, 2022

Comments

  • PHPLover
    PHPLover almost 2 years

    Hi all I'm using PHP for my website and ubuntu linux on my system. I got the above error in error.log file of apache, even after configurating everything properly. I did a lot of research on this but couldn't be able to resolve the issue. Can anyone please help me in this reagard? Following is my .htaccess file in abc directory. Can anyone please help me in this regard?

    # -FrontPage-
    
    IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
    
    <Limit GET POST>
    order deny,allow
    deny from all
    allow from all
    </Limit>
    <Limit PUT DELETE>
    order deny,allow
    deny from all
    </Limit>
    AuthName abc.org
    AuthUserFile /home/abc/public_html/_vti_pvt/service.pwd
    AuthGroupFile /home/abc/public_html/_vti_pvt/service.grp
    Options -Indexes
    
    RewriteEngine On
    RewriteRule ^alumni$ alumni.php
    RewriteRule ^student$ student.php
    RewriteRule ^view_alumni_article/view/([0-9]+)$ view_alumni_article.php?op=view&article_id=$1
    
  • Rohit Gupta
    Rohit Gupta almost 9 years
    I has the same issue and changing the permissions as above made it work. However, I am not happy about the root dir being 755. When I make it 751, it seems to work. Is this going to stuff something up ?
  • Buttle Butkus
    Buttle Butkus almost 9 years
    I believe there are exceptions to this working. If you have suphp and/or suexec, you may get an additional error if your files are writable by group. Correct me if I'm wrong.
  • Segfault
    Segfault about 8 years
    I had the same problem and instead of disabling selinux I found that sudo restorecon -R <path to site> was enough to resolve the problem.
  • Subrata Sarkar
    Subrata Sarkar over 7 years
    +1 for short and simple yet the most effective solution. I got totally screwed up with the error but your solution rocks!
  • aequalsb
    aequalsb about 7 years
    Anessh's solution worked for me... because all the other solutions above rely on selinux NOT being active -- permission problems are simply permission problems. but those solutions are meaningless if selinux is blocking everything (same with restorecon). problems on my CentOS 6 LAN web server was solved by disabling selinux -- until a power failure struck and revealed selinux settings were not saved without editing the conf file. to save selinux settings during reboots vi /etc/sysconfig/selinux find and change the line SELINUX=enabled to SELINUX=disabled reboot your MACHINE
  • Admin
    Admin over 6 years
    Solved my problem.
  • Admin
    Admin over 6 years
    It did not FIXED my problem.
  • jbrahy
    jbrahy over 5 years
    Try yum install policycoreutils-python
  • jbrahy
    jbrahy over 5 years
    You can always find the package to install using whatprovides like this. $yum whatprovides /usr/sbin/semanage
  • Scott
    Scott over 5 years
    Not having any luck with this on CentOS 7. Checked permissions, executes, ran semanage/restorecon as described. Still getting the error
  • jbrahy
    jbrahy over 5 years
    Have you rebooted? Might be something hanging.
  • gdm
    gdm about 5 years
    this is the second right answer if the first one not works.
  • gdm
    gdm over 2 years
    if the file permissions are ok, this is the right solution in redhat like distribution
  • Roberto Manfreda
    Roberto Manfreda almost 2 years
    For me, in a k8s env, running the first chmod 644 .htaccess was enough!