Link to home
Start Free TrialLog in
Avatar of gplana
gplanaFlag for Spain

asked on

problems with .htaccess on Apache2

Dear Expert:

I have installed apache2 on a Debian and add a .htaccess file with this content:

AuthUserFile /var/www/.htpasswd
AuthName "myuser"
AuthType Basic
require valid-user


I have added "myuser" linux user, and I have also created the .htpasswd file with this command:
htpasswd -c .htpasswd myuser

When I try to access to this web, it appears de authentication popup, but when enter user and password and internal Server Error is showed.

What I'm doing wrong ?

Thank you.
Avatar of JRoyse
JRoyse
Flag of United States of America image

1. I don't believe you need "AuthName 'myuser"

2.You can put a "DirectoryIndex index.html" if for example you have an index.html that it is to serve up after the Auth.

3. Does the webserver serve a page without the .htaccess file (Example: rename the .htaccess file and see if a page loads)

4. Does the apache or httpd service have enough permission to read the .htaccess and .htpasswd files?

5. Did you check in the /var/log/httpd/error.log file or equivalent after you get the error?

6. Does your .htpasswd have one line like: "myuser:sCraMbLeDChArs"

Avatar of gplana

ASKER

Thank you for your answer. I'm answering  your points ->
1. I followed instructions I found on internet
2.  Yes, this is the default configuration, so I think that is already done.
3. Yes. The webserver serve the index page if there isn't the .htaccess file. (it worked before I add the .htaccess file)
4.  .htaccess and .htpasswd have the same permisions as index.html file> rw-r--r--
5. The error log says> could not open password file> /var/www/.htpasswd
6. Yes.
 
Well, this isn't the source of your trouble, but I will point out that AuthName sets the authentication realm, not the username required, so calling it "myuser" seems a mistake. A better example would be:

AuthName "Secret Admin Area"

As the error log says "Could not open password file /var/www/.htpasswd" then it is very likely that your .htpasswd file is either not readable due to permissions, or there is no .htpasswd file on your machine in the /var/www directory. Have you checked that the owner and group of the file permits your Apache server? Use:

ls -l /var/www

to see the full details of the content of the /var/www directory, including the owner and group assigned to each file. Every time I create new documents in my /var/www directory, I have to change the owner and group to "apache" and "webdev" so that Apache can read it and I can edit it. (My user account is in the "webdev" group.) This is because files I create are automatically created with my account as owner and placed in my group.
Avatar of gplana

ASKER

I make a ls -al and, as I said before, permisions are rw-r--r--. User and group was root, and I changed to www-data, which I see is te user who executes apache2 daemons (I see that by using ps -ef). User apache doesn't exists on my system.
Problem is still the same. Any other idea ?
ASKER CERTIFIED SOLUTION
Avatar of JRoyse
JRoyse
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gplana

ASKER

I think there would be any kind of error about the pat. I changed the path for index.html and copyied .htaccess and .htpasswd files in there and it works.

Thank you for your help. It's good to know there is someone on the other side.
Weird that it didn't work as it was.

Don't forget to change the AuthName to an authentication realm rather than a username. The authentication realm is useful if you want to allow one login to be valid for more than one directory / page.
Avatar of gplana

ASKER

Sorry but.... what is an authentication realm ?