Enable htaccess in windows XAMPP?

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Enable htaccess in windows XAMPP?

Postby marksu » 31. December 2008 21:32

What is the processes to add htaccess to my windows Xampp 1.66?
I understand that there are some configuration steps before it works on windows?

My task is to reguire user for a simple password to access my virtual sites on developer machine, when
remote computer need to access the sites.

Solution is provided below. Look at the blue title "SUMMARY OF THIS THREAD".
Last edited by marksu on 01. January 2009 12:06, edited 3 times in total.
marksu
 
Posts: 20
Joined: 27. December 2008 19:12

Re: Enable htaccess in windows XAMPP?

Postby Sharley » 01. January 2009 00:28

See my post re the command line method below.

Make sure that this line is in the <Directory> directive of your vhost container in the httpd_vhosts.conf file if using a VirtualHost in a folder outside the htdocs folder:
AllowOverride All

For example:
Code: Select all
<Directory "H:\mywebsite" >
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Last edited by Sharley on 01. January 2009 01:53, edited 3 times in total.
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: Enable htaccess in windows XAMPP?

Postby marksu » 01. January 2009 01:25

Thanks for your help.
One of my problems was creating the files, but found following help on the net.

How do I make a .htaccess file on Windows?
Windows will not let you rename a file to ".htaccess". You will get an error "You must type a filename" if you try. Instead you can open the file you want to rename in a text editor, ie Notepad. Choose "Save as.." and select "All types (*.*)" next to file type. Now type the filename ".htaccess" and click save.

Well anyway not I got the files created but the site keeps popping up the user name password continuously.
Seems it does not accept the password.

The wixard creatd following pssword file paths.
AuthUserFile C:\\xampp\\htdocs\\gps/.htpasswd

That did not work so I tried following paths
C:\\xampp\\htdocs\\gps\\.htpasswd
C:\\xampp\\htdocs\\gps\.htpasswd
C:\xampp\htdocs\gps\.htpasswd

Still not accepting the password.
marksu
 
Posts: 20
Joined: 27. December 2008 19:12

Re: Enable htaccess in windows XAMPP?

Postby Sharley » 01. January 2009 01:33

Well anyway not I got the files created but the site keeps popping up the user name password continuously.
Seems it does not accept the password.
Sorry that password generator is using the Linux encyption method which is wrong encoding for XAMPP For Windows - I will edit my first post.

Tip:
Most info on the net relating to an Apache web server is Linux based and so when searching you have to specify apache for windows in your search box.


Here is a much better link that makes the correct code and that works for me:
http://www.htaccesstools.com/htaccess-authentication/

Generate the .htpasswd code then click on the .htaccess Authentication link to make the .htaccess code.
Simply copy and paste the above code over your existing .htaccess and .htpasswd files.


Command line version here:
Open a command console go to start>Run...> type cmd.exe click OK
Now type cd c:\xampp\apache\bin

You should now be in the apache bin folder and the prompt should look like this - c:\xampp\apache\bin>

Now type:
htpasswd -c -m -b c:\xampp\htdocs\gps\.htpasswd usernamehere passwordhere
Hit keyboard Enter.
Your .htpasswd file should be created in the gps folder.

Your .htaccess file should look similar to this:

AuthType Basic
AuthName "GPS"
AuthUserFile "C:\xampp\htdocs\gps\.htpasswd" <-- see note below
require valid-user


NOTE: for server security reasons the .htpasswd file should be located and referenced outside the htdocs folder and this point should be noted when creating the .htaccess file - for example AuthUserFile "C:\xampp\security\gps\.htpasswd if you put the .htpasswd file in that location - much safer.


Please let me know if all that works for you.
Also did you get the Perl Addon issue sorted out?
If so could you please let the forum know by replying in your Perl Addon topic.
Thanks
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: Enable htaccess in windows XAMPP?

Postby marksu » 01. January 2009 09:34

Hi
Thank you for your replies and help.
I got it working now with the command prompt succestion.

The second link you gave gave even worse code, but not your foult :)
path: AuthUserFile /xampp/htdocs/gps/
witch did not even have the password file named well anyway anyone reding this thread use the excellent command prompt succestions.

I think that my main problem was the password file content though. The command prompt version give a good password that works on windows.

About the perl issues I still have to tacle on that one.
I been busy and had no time to look at it, but I will get back to that as that is a important thing.
About the passwprd file location, I know that it is better to have it outside the web space path.
Just did not want to have any true paths on the forum. Good that you mensioned it as this thread has many readers.


Thank you Sharley for your excelent contribution you been doing on this forum.
You have helped many people here.

marksu
marksu
 
Posts: 20
Joined: 27. December 2008 19:12

Re: Enable htaccess in windows XAMPP?

Postby marksu » 01. January 2009 10:20


---------------------------------------------------
SUMMARY OF THIS THREAD
---------------------------------------------------


NOTE THIS IS FOR WINDOWS VERSION

My small contribution. :)

1. CREATING .htpasswd FILE

2. CREATING THE .htpasswd FILE



1. CREATING .htpasswd FILE
How do I make a .htpasswd file on Windows?
Windows will not let you rename a file to ".htpasswd ". You will get an error "You must type a filename" if you try. Instead you can open the file you want to rename in a text editor, ie Notepad. Choose "Save as.." and select "All types (*.*)" next to file type. Now type the filename ".htpasswd " and click save.

Hi are the commands for the htpasswd.exe file.


Usage:
htpasswd [-cmdps] passwordfile username
htpasswd -b[cmdps] passwordfile username password

-c Create a new file.
-m Force MD5 encryption of the password (default).
-d Force CRYPT encryption of the password.
-p Do not encrypt the password (plaintext).
-s Force SHA encryption of the password.
-b Use the password from the command line rather than prompting for it.
On Windows and TPF systems the '-m' flag is used by default.
On all other systems, the '-p' flag will probably not work.


Examples:
A. Creating a new password file with users and passwords
Add following code to a text file and rename it to createPassFile.bat.
Save it in your ../apache/bin folder.

htpasswd -c -m -b C:\xampp\passGPS\.htpasswd admin adminpass
htpasswd -m -b c:\xampp\mysitepass\.htpasswd frank frankpass
htpasswd -m -b c:\xampp\mysitepass\.htpasswd mark markpass
htpasswd -m -b c:\xampp\mysitepass\.htpasswd mary marypass

Run the file and it will create a new password file with usernames and password

B. Addin new users and passwords to existing password file
Add following code to a text file and rename it to createNewusersToPassFile.bat.
Save it in your ../apache/bin folder.

htpasswd -m -b c:\xampp\mysitepass\.htpasswd frank2 frankpass2
htpasswd -m -b c:\xampp\mysitepass\.htpasswd mark2 markpass2
htpasswd -m -b c:\xampp\mysitepass\.htpasswd mary2 marypass2

Run the file and it will create new usernames and passwords to existing password file

Note:
When removing the -c paramether the command adds new users to existing file instead of creating a new file.
The .htpasswd file is placed outside the web root for security reasons.
In the example I have created a separate folder c:\xampp\mysitepass to save the site password file.

2. CREATING THE .htaccess FILE
How do I make a .htaccess file on Windows?
Windows will not let you rename a file to ".htaccess". You will get an error "You must type a filename" if you try. Instead you can open the file you want to rename in a text editor, ie Notepad. Choose "Save as.." and select "All types (*.*)" next to file type. Now type the filename ".htaccess" and click save.

Save the ".htaccess" file in folder you want to protect.
Example c:\xampp\htdocs\<mysite>\ which will protect your entire site.

Add following code lines to ".htaccess" file.
AuthType Basic
AuthName "You need user name and password to access this folder."
AuthUserFile "C:\xampp\mysitepass\.htpasswd"
require valid-user



Conversion to linux system
I think the linux password encryptions are not same as for windows?
I could be wrong? If the password file is not working on linux system when moving you site, use
password generators that many sites offer online (easy to find using google). Most of them are for linux system.
You also need to edit the path format from C:\xampp\mysitepass\ TO something like /usr/local/you/mysitepass/ which is to be the FULL path.
I have not tested the linux version of the code yet. So if you have some corrections then I am happy to reedit the text in read or other section summary.


Thanks again Sharley :)


Regards
marksu
marksu
 
Posts: 20
Joined: 27. December 2008 19:12


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 113 guests