background : General PHP Write user authentication, are allowed any user registration, and then can log on, the user authentication needs to be manually added to the Apache server, authentication to access the contents of the directory file , not suitable for registration, only for small-scale intranet, such as Campus network
1. Modify the virtual host configuration file/usr/local/apache2/conf/extra/httpd-vhosts.conf
<directory/data/www/Test> # Home root directory set up required authentication directory
allowoverride authconfig # Open allowoverride, or select all
authname "Please input password" #描述, custom
authtype Basic # user authentication type, fixed format
AuthUserFile /data/.htpasswd #/DATA/.HTPASSWD to store authenticated users and Passwords
# The password file that Apache starts with ". HT" does not allow external reads by default
require Valid-user # Users who appear in the account password file can log in
</Directory>
Description:
The following 4 lines can also be written separately into the file . htpasswd , Conditions:
1) The file is placed under the file directory to be certified (e.g./data/www/test)
2) need to open allowoverride
3) file name fixed to. htaccess
AuthName "Please input password"
AuthType Basic
authuserfile/data/.htpasswd
Require Valid-user
2. Create a password file and user
Description: Use the HTPASSWD command to create a user, the first time you create a file with-C can be created, the second time without adding-C, otherwise it will overwrite the original file
Command htpasswd-c-m/data/.htpasswd admin # Generate user and password in/data/.htpasswd file
Command Htpasswd-m/data/.htpasswd admin1
3. Testing
Restart Apache, browser input/HTTP/website/test
This article is from "A horse on the Plains" blog, please be sure to keep this source http://huangzp.blog.51cto.com/12434999/1906875
Apache user authentication