Integrate Apache with MySQL for basic identity authentication

Source: Internet
Author: User
Tags mysql host
There are many ways to implement basic user identity authentication in Apache, such as the most common txt text and DBM pattern, but on servers with heavy loads-these are not imaginary methods, the text is flat-based, with poor performance and security. DBM is better, but it is still insufficient for thousands or tens of thousands of users.

There are many ways to implement basic user identity authentication in Apache, such as the most common txt text and DBM pattern, but on servers with heavy loads-these are not imaginary methods, the text is based on a plane, with poor performance and security. DBM is better, but it is still insufficient for thousands or tens of thousands of users, therefore, using the database for background storage is a good method-it is more effective and secure than the flat search, and the user password is stored in the database table with DES encryption.

This implementation is successful in the excellent modular structure of Apache itself-as well as the open DSO method, which enables developers to complete a large number of third-party modules and expand the efficacy of Apache. In this article, I only wrote about using Mysql for backend storage-in addition, Postgresql, Oracle, and so on can be used for the same principle-both use their respective modules.

Let's get started -- first go to modules.apache.org and find mod_auth_mysql -- there will be two ones we will use DSO-in fact, directly go to the Compile (the previous question is the Apache compiled in DSO mode) -- apxs-c-I-a-L/usr/local/lib/mysql-lmysqlclient>-lm mod_auth_mysql.c -- be sure to write this here --- L/usr/local/lib/ mysql is the customer database of mysql, I suppose mysql is installed by default.) --- If Apache is not started, an error is reported-this module cannot be loaded.

Let's take a look at httpd. conf. There should be LoadModule mysql_auth_module libexec/mod_auth_mysql.so and AddModule mod_auth_mysql.c, and Apache should not have a title again.

Then we enter mysql, mysql> create database auth;


mysql>use auth;mysql> create table mysql_auth (-> user_name char(20) not null,-> user_passwd char(25),-> groups char(25),-> primary key (username) );

Note that the field names must be user_name and user_passwd. Insert several more records:


mysql> insert into mysql_auth values('xingfei2',encrypt('abcde'),'xingfei');Query OK, 1 row affected (0.00 sec)mysql> insert into mysql_auth values('xingfei',encrypt('abcde'),'xingfei');Query OK, 1 row affected (0.00 sec)

Here, abcde is the password-encryption using the encrypt function, using the DES algorithm-this is the same as the unix password algorithm-rather than the password () function encrypted by mysql itself.

Finally, create a. htaccess (do not forget to open AllowOverride all) in the directory to be protected. the content is as follows:


Authname 'xingfei' authtype basicAuthMySQLHost localhost --- mysql host name authmysqluser root --- mysql User authmysqlpassword abc --- mysql User password AuthMySQLDB auth --- user's library-that is, the database we created AuthMySQLUserTable mysql_auth --- used table AuthMySQLGroupField groups --- field name of the user group require group xingfeirequire user xingfei
 

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.