How to Configure Your Website Using Htaccess in Linux with Apache
For this to work successfully you will have to be logged in as root or using one of the sudo or su options., We will need to create the folder that will have to be authenticated., Next we need to add the .htaccess & .htpasswd files to the personal...
Step-by-Step Guide
-
Step 1: For this to work successfully you will have to be logged in as root or using one of the sudo or su options.
Since the default location in apache is /var/www/html we will create it here.
You will do this by using the mkdir command. # mkdir /var/www/html/testfolder , We first need to change the directory of the folder we wish to protect. # cd /var/www/html/testfolder , # vi .htaccess , AuthUserFile /var/www/html/testfolder/.htpasswd AuthGroupFile /www.null AuthName "Authorization Required" AuthType Basic require user USER_NAME ,,, We want to run htpasswd on the path of the folder we want to protect. # htpasswd
-c /var/www/html/testfolder/.htpasswd USER_NAME ,, To do this use "ls
-a" in your command prompt. , # vi /etc/httpd/conf/httpd.conf , #FOR MY TEST FOLDER <Directory "/var/www/html/testfolder"> AllowOverride AuthConfig </Directory>
and restart apache. # service httpd restart -
Step 2: We will need to create the folder that will have to be authenticated.
-
Step 3: Next we need to add the .htaccess & .htpasswd files to the personal folder.
-
Step 4: Next we can create the .htaccess file.
-
Step 5: Press i to insert and add the following content.
-
Step 6: Change "test folder" to the name of your folder and change "USER_NAME" to the user name you wish to use.
-
Step 7: Press your esc button then :wq to save your file in your vi editor.
-
Step 8: Next we'll create the .htpasswd file.
-
Step 9: You should see something like this: # htpasswd -c /var/www/html/testfolder/.htpasswd USER_NAME New password: Re-type new password: Adding password for user USER_NAME
-
Step 10: Verify that these file were created in your testfolder directory.
-
Step 11: Next we will have to edit the apache httpd.conf (on some systems called the apache2.conf) file.
-
Step 12: You will have to scroll all the way to the bottom to add the following directory.
-
Step 13: Finally save httpd.conf by typing esc :qw!
Detailed Guide
Since the default location in apache is /var/www/html we will create it here.
You will do this by using the mkdir command. # mkdir /var/www/html/testfolder , We first need to change the directory of the folder we wish to protect. # cd /var/www/html/testfolder , # vi .htaccess , AuthUserFile /var/www/html/testfolder/.htpasswd AuthGroupFile /www.null AuthName "Authorization Required" AuthType Basic require user USER_NAME ,,, We want to run htpasswd on the path of the folder we want to protect. # htpasswd
-c /var/www/html/testfolder/.htpasswd USER_NAME ,, To do this use "ls
-a" in your command prompt. , # vi /etc/httpd/conf/httpd.conf , #FOR MY TEST FOLDER <Directory "/var/www/html/testfolder"> AllowOverride AuthConfig </Directory>
and restart apache. # service httpd restart
About the Author
Kathleen Butler
Professional writer focused on creating easy-to-follow practical skills tutorials.
Rate This Guide
How helpful was this guide? Click to rate: