Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 626
  • Last Modified:

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.
0
gplana
Asked:
gplana
  • 4
  • 2
  • 2
1 Solution
 
JRoyseCommented:
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"

0
 
gplanaAuthor Commented:
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.
 
0
 
HackneyCabCommented:
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gplanaAuthor Commented:
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 ?
0
 
JRoyseCommented:
read permission should work without any trouble - maybe there is a typo or space in the names.

I would change the .htaccess to read: AuthUserFile /var/www/user-list

and then copy the .htaccess to /var/www/user-list

Make sure the file permissions opened up - then try again.  
0
 
gplanaAuthor Commented:
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.
0
 
HackneyCabCommented:
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.
0
 
gplanaAuthor Commented:
Sorry but.... what is an authentication realm ?
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now