Apache user authentication

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.