Apache - Configure htaccess for Apache

December 2016




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
</Directory>


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
</Limit>


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.

Notes


Thanks to wjaouadi for this tip

Related :

This document entitled « Apache - Configure htaccess for Apache » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.