Apache - Configure htaccess for Apache

This tip explains how to configure an access via htaccess. This allows password secured access to web directories.

Update http.cond

We must add the following statement in Web Folders to protect:

<Directory /yourdirectory/web>
Options Indexes Includes FollowSymlinks MultiViews
AllowOverride AuthConfig
Order allow,deny
Allow from all

The AllowOverride AuthConfig primitives configure Apache to take into account the .htaccess file in the web directory and its subdirectories.

The .htaccess file

With a text editor create a .htaccess file under the directory to be protected, containing the following lines:

AuthUserFile /path/to/.htpasswd
AuthName "protected access"
AuthType Basic

<Limit GET POST>
Require valid-user

The .htpasswd contains the logins and passwords.

Creatinf the .htpasswd file

To create the file. htpasswd file, simply run the command

# htpasswd -c /path/to/.htpasswd user

The htpasswd command is present in the bin directory of Apache, the -c option creates the file, note that you must specify the user name and password to the application.
The file is created by the command, from there restart Apache.


Thanks to wjaouadi for this tip

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Apache - Configure htaccess for Apache », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).