|
Home > Archive > Apache Server configuration support > May 2006 > Newbie: .htaccess basic config not working
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Newbie: .htaccess basic config not working
|
|
|
| I've looked at the Apache Core Features doc at:
http://httpd.apache.org/docs/1.3/mod/core.html
and I've made the following changed to my /etc/httpd/conf/httpd.conf file:
AllowOverride All
AccessFileName .htaccess
Options All
I'm trying to password-protect this directory:
home/myusername/public_html/admin
here is the .htacecss file currently in the admin directory:
AuthType Basic
AuthName "admin"
AuthUserFile "/home/myusername/.htpasswds/admin/passwd"
require valid-user
Options All -Indexes
The passwd file has this:
myusername:dUfedloe6dfUT
I must be missing something because it is not working - access to the admin
directory is unrestricted.
Why is .htaccess not working?
Also - How do I set/change the password?
Thanks in advance.
| |
|
| > AllowOverride All
> AccessFileName .htaccess
> Options All
The documentation is not clear which section of httpd.conf needs to be edited.
I have a few different <Directory /> blocks in my httpd.conf. Which one should
I edit?
My guess is one of these two:
### Section 2: 'Main' server configuration
User apache
Group apache
ServerAdmin root@localhost
UseCanonicalName Off
DocumentRoot "/home/my-user-name/public_html"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/home/my-user-name/public_html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
But which one? And why are there two, one right after another? Do I need both?
Why?
| |
|
| In case anyone else needs to pass this way...
How to password protect a directory using .htaccess on an Apache server
1. Log into your server as root
2. Edit your httpd.conf file
web-server [/] # cd /etc/httpd/conf
web-server [/etc/httpd/conf] # ls -luchFa
drwxr-xr-x 7 root root 4.0K May 26 16:53 ./
drwxr-xr-x 4 root root 4.0K May 4 06:04 ../
-rw-r--r-- 1 root root 7.1K May 26 16:25 httpd.conf
-rw-r--r-- 1 root root 13K May 4 06:04 magic
lrwxrwxrwx 1 root root 37 May 4 06:04 Makefile ->
.../../../usr/share/ssl/certs/Makefile
drwx------ 2 root root 4.0K May 4 06:04 ssl.crl/
drwx------ 2 root root 4.0K May 4 06:04 ssl.crt/
drwx------ 2 root root 4.0K May 4 06:04 ssl.csr/
drwx------ 2 root root 4.0K May 4 06:04 ssl.key/
drwx------ 2 root root 4.0K May 4 06:04 ssl.prm/
web-server [/etc/httpd/conf] # vi httpd.conf
### Section 2: 'Main' server configuration
User apache
Group apache
ServerAdmin root @ localhost
UseCanonicalName Off
DocumentRoot "/home/boyjojo/public_html"
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory "/home/boyjojo/public_html">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
#<Directory "/home/boyjojo/public_html">
# Options Indexes FollowSymLinks
# AllowOverride None
# Order allow,deny
# Allow from all
#</Directory>
3. Create the directory in which the password file will reside
Note: best practice is to create the password file outside of DocumentRoot
web-server [/home/boyjojo/public_html] # cd ..
web-server [/home/boyjojo] # ls -luchFa
-rw------- 1 boyjojo boyjojo 2.4K May 26 16:45 .bash_history
-rw-r--r-- 1 boyjojo boyjojo 24 May 13 20:27 .bash_logout
-rw-r--r-- 1 boyjojo boyjojo 191 May 13 20:27 .bash_profile
-rw-r--r-- 1 boyjojo boyjojo 887 May 25 00:02 .bashrc
-rw------- 1 boyjojo boyjojo 1.1K May 23 23:17 .mysql_history
drwxrwxrwx 19 boyjojo boyjojo 4.0K May 26 12:19 public_html/
-rw------- 1 boyjojo boyjojo 5.7K May 26 16:44 .viminfo
web-server [/home/boyjojo] # mkdir .htpasswds
web-server [/home/boyjojo] # cd .htpasswds
web-server [/home/boyjojo/.htpasswds] # mkdir admin
web-server [/home/boyjojo/.htpasswds] # cd ..
web-server [/home/boyjojo] # ls -luchFa
-rw------- 1 boyjojo boyjojo 2.4K May 26 16:45 .bash_history
-rw-r--r-- 1 boyjojo boyjojo 24 May 13 20:27 .bash_logout
-rw-r--r-- 1 boyjojo boyjojo 191 May 13 20:27 .bash_profile
-rw-r--r-- 1 boyjojo boyjojo 887 May 25 00:02 .bashrc
drwxr-xr-x 3 root root 4.0K May 26 20:20 .htpasswds/
-rw------- 1 boyjojo boyjojo 1.1K May 23 23:17 .mysql_history
drwxrwxrwx 19 boyjojo boyjojo 4.0K May 26 12:19 public_html/
-rw------- 1 boyjojo boyjojo 5.7K May 26 16:44 .viminfo
web-server [/home/boyjojo] #
4. Create a password file using the htpasswd utility
web-server [/home/boyjojo] # htpasswd -c /home/boyjojo/.htpasswds/admin/passwd
boyjojo
New password:
Re-type new password:
Adding password for user boyjojo
5. Create the .htaccess file in the directory you want to password-protect
web-server [/home/boyjojo] # cd public_html/admin
web-server [/home/boyjojo/public_html/admin] # vi .htaccess
AuthType Basic
AuthName "admin"
AuthUserFile "/home/boyjojo/.htpasswds/admin/passwd
require valid-user
Options All -Indexes
6. Set owner, group, and permissions on the password file
web-server [/home/boyjojo] # ls -luchFa
-rw------- 1 boyjojo boyjojo 2.4K May 26 16:45 .bash_history
-rw-r--r-- 1 boyjojo boyjojo 24 May 13 20:27 .bash_logout
-rw-r--r-- 1 boyjojo boyjojo 191 May 13 20:27 .bash_profile
-rw-r--r-- 1 boyjojo boyjojo 887 May 25 00:02 .bashrc
-rw------- 1 boyjojo boyjojo 1.1K May 23 23:17 .mysql_history
drwxrwxrwx 19 boyjojo boyjojo 4.0K May 26 12:19 public_html/
-rw------- 1 boyjojo boyjojo 5.7K May 26 16:44 .viminfo
web-server [/home/boyjojo] # chown -R apache .htpasswds
web-server [/home/boyjojo] # chgrp -R apache .htpasswds
web-server [/home/boyjojo] # ls -luchFa
total 44K
drwxrwxrwx 4 root 500 4.0K May 26 20:24 ./
drwxrwxrwx 4 root root 4.0K May 12 02:34 ../
-rw------- 1 boyjojo boyjojo 2.4K May 26 16:45 .bash_history
-rw-r--r-- 1 boyjojo boyjojo 24 May 13 20:27 .bash_logout
-rw-r--r-- 1 boyjojo boyjojo 191 May 13 20:27 .bash_profile
-rw-r--r-- 1 boyjojo boyjojo 887 May 25 00:02 .bashrc
drwxr-xr-x 3 apache apache 4.0K May 26 20:25 .htpasswds/
-rw------- 1 boyjojo boyjojo 1.1K May 23 23:17 .mysql_history
drwxrwxrwx 19 boyjojo boyjojo 4.0K May 26 12:19 public_html/
-rw------- 1 boyjojo boyjojo 5.7K May 26 16:44 .viminfo
web-server [/home/boyjojo] # chmod -R 755 .htpasswds
7. Stop and restart the httpd daemon
web-server [/home/boyjojo] # service httpd stop; service httpd start
| |
| Robert Ionescu 2006-05-29, 5:40 pm |
| deko wrote:
> The documentation is not clear which section of httpd.conf needs to be
> edited. I have a few different <Directory /> blocks in my httpd.conf.
[...]
> But which one? And why are there two,
The first one, <directory />, is a restrictive one which applies to your
whole file system. Usually it should contain a 'deny from all', do deny
access by default. Now with special ones like <Directory
"/home/my-user-name/public_html"> you're allowing access for certain
directories.
In order to protect a specific directory, just use eg.
<Directory "/home/my-user-name/public_html/admin">
AuthType Basic
AuthName "admin"
AuthUserFile "/home/myusername/.htpasswds/admin/passwd"
require valid-user
</Directory>
in your httpd.conf. There is no need to use a .htaccess file.
http://httpd.apache.org/docs/2.2/ho...ccess.html#when (When (not) to
use .htaccess files)
--
Robert
| |
|
| > The first one, <directory />, is a restrictive one which applies to your
> whole file system. Usually it should contain a 'deny from all', do deny
> access by default. Now with special ones like <Directory
> "/home/my-user-name/public_html"> you're allowing access for certain
> directories.
Thanks for the tip.
So the one to modify is the second one, like this:
#no changes here
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
#changes here
<Directory "/home/boyjojo/public_html">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
> There is no need to use a .htaccess file.
I am going to use .htaccess... and will kill anyone that tries to stop me.
|
|
|
|
|