Jadey
sosumi
This How-to will tell you how to get Apache to prompt your users for a username & password when they try and look at a directory you've secured.
As with all things Apache, start by editing the configuration file. This is in /private/etc/httpd
Launch a terminal.
Type: cd /private/etc/httpd
Type: sudo pico httpd.conf
(You can use a different text editor if you wish, other than pico).
Scroll down until you reach the AuthConfig section. It will look like this:
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
AllowOverride None
Change that last line to:
AllowOverride All
Save the httpd.conf file. If you're using pico, this is done by holding down control and hitting x.
Now, back in the terminal, type:
sudo htpasswd -c .htpasswd username
The username can be named what you like. For example, if you want people to be prompted for the username "friend" you would enter friend instead of username.
This command will also prompt you for the password you want to use.
Now in the terminal, type:
cd /Library/WebServer/Documents/DirectoryYouWannaSecure
Substitute "DirectoryYouWannaSecure" for the name of the folder you want people to have to type in a username & password to access. Or substitute the path to your own user's Sites directory.
In the terminal, type: sudo pico .htaccess
(again, you can use a different text editor than pico if you wish).
In the .htaccess file you just created with pico, paste this:
AuthUserFile /private/etc/httpd/.htpasswd
AuthGroupFile /dev/null
AuthName "Members Only"
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>
Save this file. Again control-x if in pico.
Restart Apache: sudo apachectl restart
(or turn it off & on with the button in your Sharing control panel)
Now when you go to http://localhost/DirectoryYouWannaSecure you'll be asked for a username & password!
As with all things Apache, start by editing the configuration file. This is in /private/etc/httpd
Launch a terminal.
Type: cd /private/etc/httpd
Type: sudo pico httpd.conf
(You can use a different text editor if you wish, other than pico).
Scroll down until you reach the AuthConfig section. It will look like this:
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
AllowOverride None
Change that last line to:
AllowOverride All
Save the httpd.conf file. If you're using pico, this is done by holding down control and hitting x.
Now, back in the terminal, type:
sudo htpasswd -c .htpasswd username
The username can be named what you like. For example, if you want people to be prompted for the username "friend" you would enter friend instead of username.
This command will also prompt you for the password you want to use.
Now in the terminal, type:
cd /Library/WebServer/Documents/DirectoryYouWannaSecure
Substitute "DirectoryYouWannaSecure" for the name of the folder you want people to have to type in a username & password to access. Or substitute the path to your own user's Sites directory.
In the terminal, type: sudo pico .htaccess
(again, you can use a different text editor than pico if you wish).
In the .htaccess file you just created with pico, paste this:
AuthUserFile /private/etc/httpd/.htpasswd
AuthGroupFile /dev/null
AuthName "Members Only"
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>
Save this file. Again control-x if in pico.
Restart Apache: sudo apachectl restart
(or turn it off & on with the button in your Sharing control panel)
Now when you go to http://localhost/DirectoryYouWannaSecure you'll be asked for a username & password!