Apache - Configure htaccess for Apache

April 2018

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
Published by jak58. Latest update on December 9, 2009 at 03:58 AM by jak58.
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 (https://ccm.net/).
Gentoo Linux - Installing Apache2/PHP
Configuring Apache and Windows to create a virtual host