Solved

problems with .htaccess on Apache2

Posted on 2010-08-20
8
610 Views
Last Modified: 2013-11-05
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
Comment
Question by:gplana
  • 4
  • 2
  • 2
8 Comments
 
LVL 6

Expert Comment

by:JRoyse
ID: 33487898
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
 
LVL 15

Author Comment

by:gplana
ID: 33488601
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
 
LVL 16

Expert Comment

by:HackneyCab
ID: 33489805
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 15

Author Comment

by:gplana
ID: 33492828
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
 
LVL 6

Accepted Solution

by:
JRoyse earned 500 total points
ID: 33501367
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
 
LVL 15

Author Closing Comment

by:gplana
ID: 33502611
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
 
LVL 16

Expert Comment

by:HackneyCab
ID: 33502658
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
 
LVL 15

Author Comment

by:gplana
ID: 33503632
Sorry but.... what is an authentication realm ?
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question