Apache logs "pcfg_openfile: unable to check htaccess file" for a site
(13)Permission denied: /var/www/abc/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readableShort answer
Apache runs as its own user, not as you. The error means that user cannot read the .htaccess file or cannot enter one of the folders above it. Run namei on the full path, give every folder execute permission for the Apache user, and make the .htaccess file readable.
Fix it fast
1Find out which cause you have
Show the owner and permissions of every folder on the way to the file. The first entry that the Apache user cannot pass or read is the problem.
namei -l /var/www/abc/.htaccess2Match what you see, then jump to its fix
- 1
namei shows a parent folder such as /home/user with mode rwx------ or rwxr-x---A folder above the site has no execute (search) permission for ApacheFix - 2
namei shows the folders are fine, but the file mode is rw------- and owner is another userThe .htaccess file itself is not readable by the Apache userFix - 3
Permissions look right for www-data but the files belong to another accountApache runs as a different user than you assumedFix
- 1
What does the error look like?
(13)Permission denied: /var/www/abc/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readablepcfg_openfile: unable to check htaccess file
Cause 1 of 3
A folder above the site has no execute (search) permission for Apache
1Check
On a directory the execute bit is the search bit. Without it the kernel refuses to look inside, and the error code is EACCES, which is exactly (13) Permission denied.
namei -m /var/www/abc/.htaccess
ps -o user= -C apache2 | sort -u2Fix
Give others (or the group Apache belongs to) execute on each folder in the path. Use a group when you do not want everyone to enter.
sudo chmod o+x /home/user
# or, with a group:
sudo chgrp www-data /home/user && sudo chmod g+x /home/user3Verify
Run namei again and reload the site.
namei -m /var/www/abc/.htaccess && curl -I http://localhost/Confirmed by man7.org
Cause 2 of 3
The .htaccess file itself is not readable by the Apache user
1Check
Apache switches to the user set by the User directive to serve requests, so that user needs read permission on the file. List the file with owner and mode.
ls -l /var/www/abc/.htaccess
ps -o user= -C apache2 | sort -u2Fix
Make the file readable and keep it writable only by its owner.
sudo chmod 644 /var/www/abc/.htaccess3Verify
Request the site again. The error no longer appears in the log.
curl -I http://localhost/Confirmed by httpd.apache.org
Cause 3 of 3
Apache runs as a different user than you assumed
1Check
The ps command from the first cause shows who the worker processes run as. If a custom User or Group is set, grant access to that account, not to the default one.
ps -o user=,group= -C apache2 | sort -u2Fix
Use the actual user and group in your chown or chgrp commands, or change User and Group in the Apache configuration, then reload.
sudo chgrp -R <apache-group> /var/www/abc
sudo systemctl reload apache23Verify
Run namei again and request the site.
namei -l /var/www/abc/.htaccessConfirmed by httpd.apache.org
How do I stop it coming back?
- Keep sites under /var/www or another path where every parent folder is readable to the web server.
- Deploy files with a fixed owner and group so permissions do not change after uploads.
- Check new virtual hosts with namei before the first request.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
Apache warns that a ${VAR} config variable is not defined
${VAR} left unchanged in the configuration, with a warning in the error log
Apache expands ${VAR} from Define or from the shell environment that exists when the server starts.
3 causes, each with a fix