HTAccess HTpasswd – Permission Denied: Could Not Open Password File

.htaccesshtpasswd

I am using Apache Red hat .

I have .htaccess in my /var/www/html with permissions as followed

-rwxr-xr-x. 1 apache apache 127 Dec 18 14:17 .htaccess

.htaccess has following data set inside it

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /var/www/html/server-auth/.htpasswd
Require user manu

Permissions on var/www/html/server-auth/.htpasswd

-rwxr-xr-x. 1 apache apache 40 Dec 16 19:11 .htpasswd

When I open my web page on browser, and after putting username and password, the login prompts reappears. Even if the username and password is correct.

Error logs:

(13) Permission denied: Could not open password file: /var/www/html/server-auth/.htpasswd

access to / failed, reason: verification of user id 'manu' not configured

Any help!

Best Answer

You are having this problem because of SELinux security context.

To overcome this you need to change the selinux label of the directory/file in question.

You can find out the apache process security context using ps axZ | grep httpd.

And check the same for ls -Z /var/www/html/server-auth/.htpasswd

To adjust the directory labeling try: chcon command (it's like chown). To make it permanent you may use: semanage command.

Detail instructions and a must read here: https://wiki.centos.org/HowTos/SELinux