Configure Your Website Using Htaccess in Linux with Apache
.htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
Steps
- 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. Since the default location in apache is /var/www/html we will create it here. You will do this by using the mkdir command. Template:CodeBox
- Next we need to add the .htaccess & .htpasswd files to the personal folder. We first need to change the directory of the folder we wish to protect. Template:CodeBox
- Next we can create the .htaccess file. Template:CodeBox
- Press i to insert and add the following content. Template:CodeBox
- Change "test folder" to the name of your folder and change "USER_NAME" to the user name you wish to use.
- Press your esc button thenĀ :wq to save your file in your vi editor.
- Next we'll create the .htpasswd file. We want to run htpasswd on the path of the folder we want to protect. Template:CodeBox
- You should see something like this: Template:CodeBox
- Verify that these file were created in your testfolder directory. To do this use "ls -a" in your command prompt.
- Next we will have to edit the apache httpd.conf (on some systems called the apache2.conf) file. Template:CodeBox
- You will have to scroll all the way to the bottom to add the following directory. Template:CodeBox
- Finally save httpd.conf by typing escĀ :qw! and restart apache. Template:CodeBox
Related Articles
- Set up a Network in Ubuntu
- Move from Windows to Linux
- Install WAMP
- Install and Configure Apache Webserver to Host a Website from Your Computer
- Install the PHP Engine on Your Windows PC