Add password to website using apache web server
Adding password to a website or web directory using Apache web server is easy, for CentOS and other RedHat-based distro, edit your /etc/httpd/conf/httpd.conf and find the line AllowOverride None under <Directory "/var/www/html"> and replace with AllowOverride All.
Then after this line Allow from all add these following lines:
AuthName "Login Message Here" AuthType Basic AuthUserFile /var/www/html/htpasswd.users Require valid-user
Your apache config file should look like this:
- <Directory "/var/www/html">
- #
- # Possible values for the Options directive are "None", "All",
- # or any combination of:
- # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
- #
- # Note that "MultiViews" must be named *explicitly* --- "Options All"
- # doesn't give it to you.
- #
- # The Options directive is both complicated and important. Please see
- # http://httpd.apache.org/docs-2.0/mod/core.html#options
- # for more information.
- #
- Options Indexes FollowSymLinks
- #
- # AllowOverride controls what directives may be placed in .htaccess files.
- # It can be "All", "None", or any combination of the keywords:
- # Options FileInfo AuthConfig Limit
- AllowOverride All
- #
- # Controls who can get stuff from this server.
- #
- Order allow,deny
- Allow from all
- AuthName "Login Message Here"
- AuthType Basic
- AuthUserFile /var/www/html/htpasswd.users
- Require valid-user
- </Directory>
Same configuration for Debian Linux, edit the file /etc/apache2/sites-enabled/000-default.
Find the line AllowOverride None under the <Directory /var/www/> and change to AllowOverride All.
Add these following lines:
AuthName "Login Message Here" AuthType Basic AuthUserFile /var/www/html/htpasswd.users Require valid-user
after the line that says allow from all.
- <Directory /var/www/>
- Options Indexes FollowSymLinks MultiViews
- AllowOverride All
- Order allow,deny
- allow from all
- AuthName "Login Message Here"
- AuthType Basic
- AuthUserFile /var/www/htpasswd.users
- Require valid-user
- # This directive allows us to have apache2's default start page
- # in /apache2-default/, but still have / go to the right place
- #RedirectMatch ^/$ /apache2-default/
- </Directory>
Create the password file htpasswd.users file, your password will be stored in this file. To create a password for your username, type this command in the console.
or for Debian
htpasswd -c htpasswd.users username
You can also use the .htaccess file to protect your web directory, just create a .htaccess file inside the web directory you want to secure and put these following lines:
AuthName "Login Message Here" AuthType Basic AuthUserFile /var/www/html/htpasswd.users Require valid-user
After you have created the .htaccess file, create a password for your username, just type this command:
This will require your web site visitors to login with a user id and password. If they failed to enter the specified username and password, the browser will display an error message.
That's how it works... Cheers!!!


Delicious
Digg
StumbleUpon
Furl
Facebook
Twitter
Google
Yahoo
Buzz Up!
LinkedIn
Technorati



Comments
I'm trying to open forum but sometimes there are no images on it :(
[...] any authentication. If you want to put an authentication to your Asterisk-stat, just follow this howto. It will require web site visitors to login with a user id and [...]
Post new comment