Fix password protected folder 500 server error

Web programming qustions, like PHP, ASP, ASP .NET, Perl etc. belong in this section.
Forum rules
Please make yourself familiar with our rules and guidelines before posting.
Post Reply
Posts: 1350
Joined: Fri Nov 08, 2019 12:11 pm
Latest blog post: The magical little can that replaces 4 pantry item...
Answers: 2
Reputation: 617
Location: Central Kentucky USA
Has thanked: 149 times
Been thanked: 42 times

Fix password protected folder 500 server error

Post by Colbyt »

This is how to fix password protected folder 500 server error problem on localhost, Linux server or VPS.

Before I make blanket statement in the next paragraph I need to clarify that all testing was performed using Apache2 (V2.4) on an xampp localhost and a Ubuntu 18.04 server and this post is based on the results of those tests. Neither have control panels like cPanel. cPanel makes this job simple but is just a tad pricey for most self managed VPS users.

If you have a VPS or dedicated server, are manually trying to follow online tutorials and keep getting 500 errors. It is because all the tutorials on the first page of Google results are providing you with bad information. All of them say something like:
Create a .htaccess file
Use a plain text editor (eg an ASCII text editor) like Notepad to create a text file with the following contents:

AuthName "Members Only Area"
AuthType Basic
AuthUserFile /path/to/your/directory/.htpasswd
require valid-user
If you leave any spaces in "Members Only Area" you will get a 500 error and an entry into your Apache error log that reads something like this
[Tue Jun 02 08:08:24.193066 2020] [core:alert] [pid 9504:tid 1924] [client ::1:53296] C:/xampp/htdocs/temp/admin/.htaccess: AuthName takes one argument, the authentication realm (e.g. "Members Only")
One argument means one word or words connected with an _ underscore.

You can use Members_Only_Area if that is what you want it to read but you can't leave spaces. The quotes are not needed and if used will display as part of the name.

Xampp will allow to use a plain text password but a live server forces encryption. Also you can not copy the .htpasswd from localhost to a live server or from one server to another*. You must follow the directions to create the user and password on the server you intend to use it on.

*Edit: I may have been wrong when I said "or from one server to another." As I did do that where both servers were running the same version of Apache and it worked.
Reducing my online presence to do some other things.

Post Reply

Return to “Web Programming”

Who is online

Users browsing this forum: No members and 7 guests