Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to set up basic authentication for a linux (centos) server.

I did the following:

mkdir /usr/local/apache
mkdir /usr/local/apache/passwd
echo > /usr/local/apache/passwd/passwords
htpasswd -c /usr/local/apache/passwd/passwords some_user
new password: xxxxxx
confirm password: xxxxxx

Here's the virtual host section:

NameVirtualHost *:80

ServerName localhost 
ServerAdmin webmaster@localhost

DocumentRoot /var/www/mysite/web/
<Directory />
    Options FollowSymLinks
    AllowOverride None

    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all

Alias /winapi /var/www/another_section/
<Directory "/var/www/another_section">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all

Where do the basic authentication directives go? (to provide basic authentication protection to the entire virtual host):

    AuthType Basic
    AuthName "Restricted Access"
    AuthUserFile /usr/local/apache/passwd/passwords
    Require user some_user      
share|improve this question
. . . Have you read the Apache manual? there's a whole section on this that tells you where to place the directives (Inside an appropriate <Directory> context, possibly several of them...) – voretaq7 Nov 14 '12 at 19:11
what kind of authentication are you trying to do? Simpler would be to use some directory server such as openldap or 389 – chandank Nov 14 '12 at 19:24
I am not a sysadmin, but I am required to do this for a client (and the requirement is to use basic authentication). I don't have time to read large sections of the Apache manual, I used all my available hours to get to the state I described in my question. I guess if this is a hardcore server forum, and there is no room for those who may have an occasional question, but don't make a living as sysadmins, then I'll continue researching the issue – EastsideDeveloper Nov 14 '12 at 19:44

The basic authentication goes in your <Directory> block.

share|improve this answer
Thanks, can you elaborate on your answer and perhaps add a link succinct link to the appropriate documentation (not required)? – Felix Frank Aug 5 '14 at 15:20
You could also put it in a .htaccess file. – joeg1ff Aug 5 '14 at 15:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.