Get the App
SLTechnology News&Howtos  ›  Database  › 

How to realize Apache user Authentication by MySQL

Shulou Source: shulou.com Published: 2022-05-31 15:33:06 11月08日 Update

This article mainly introduces MySQL how to achieve Apache user authentication, the article is very detailed, has a certain reference value, interested friends must read it!

Apache requires DSO to compile and install, assuming that apache is installed in the / usr/local/apache directory and mysql in the / usr/local/mysql directory

First download mod_auth_mysql at http://www.bruce.com.cn/software... _ mysql-2.9.0.tar.gz

[root@www software] # tar xzfv mod_auth_mysql-2.9.0.tar.gz

[root@www software] # cd mod_auth_mysql-2.9.0

[root@www mod_auth_mysql-2.9.0] # / usr/local/apache/bin/apxs-c-I/usr/local/mysql/include-L/usr/local/mysql/lib-lmysqlclient-lm-lz mod_auth_mysql.c

[root@www mod_auth_mysql-2.9.0] # / usr/local/apache/bin/apxs-I mod_auth_mysql.la

Then edit the httpd.conf file

[root@www mod_auth_mysql-2.9.0] # vi / usr/local/apache/conf/httpd.conf

Add the following lines to httpd.conf: (the following is an excerpt from my httpd.conf)

LoadModule mysql_auth_module modules/mod_auth_mysql.so

AuthType Basic

AuthMySQLHost localhost

AuthMySQLPort 3306

AuthMySQLDB database # Database to be accessed

AuthMySQLUser mysql_user # users accessing the database

AuthMySQLPassword user_password # user password

AuthMySQLPwEncryption md5 # MD5 encryption

AuthMySQLEnable On

AuthMySQLUserTable user_table # data tables to be accessed

Fields of AuthMySQLNameField username # username

AuthMySQLPasswordField password # password field

AuthMySQLGroupTable user_table # is the same as user table

AuthMySQLGroupField mygroup # user Group Field

As you can see from the above configuration, this module actually has no special requirements for the user table, as long as you can find the user name and the corresponding password, and if you need to authenticate a group, you need the group column.

Since all users within the company have the same group, it is common to use group users to authenticate, so add the column: user_group to the plog_user table and update the user_group column of all rows to a solid

A fixed value, such as mygroup.

Here groupTable and UserTable are the same table, and if you need a user to belong to more than one group, you must create a separate group table.

After you have done the above work, add the .htaccess file to the directory that needs to be encrypted as follows:

[root@www MySQL] # more / home/bruce/html/software/.htaccess

AuthType Basic

AuthName "Resource downloads are for members only"

Require valid-user

Restart apache again

[root@www mod_auth_mysql-2.9.0] # service httpd restart

After adopting this authentication measure, users' browsing records can be retained in the Apache log, and users' browsing times can be seen by using log statistics software such as awstats, so that the knowledge flow within the company can be seen clearly.

The above is all the content of the article "how to achieve Apache user authentication in MySQL". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: User authentication field data directory authentication company content password database file log user name knowledge article user table encryption browsing clear same Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno Shulou Information Docker Apple