Type : System
Operating System : Redhat,Fedora,Centos
This mini howto explain how to install mod_auth_mysql on redhat, centos or fedora core server.
Mod_auth_mysql is a very simple module to authorize a user in function of the group to access at defined part of your web application.
SUMMARY
#yum install mod_auth_mysql
Now the module is install and ready for the mysql and database creation.
Database creation for mysql :
The mysql schema is defined for authentification by a user and a group definition.
You can find another schema, if you want only a user authentification or you have a choice to define your own mysql schema or you own mysql condition.
#mysql -u root -p
mysql>CREATE DATABASE auth;
mysql>USE auth;
mysql>CREATE TABLE users (
user_name CHAR(30) NOT NULL,
user_passwd CHAR(20) NOT NULL,
PRIMARY KEY (user_name)
);
mysql>CREATE TABLE groups (
user_name CHAR(30) NOT NULL,
user_group CHAR(20) NOT NULL,
PRIMARY KEY (user_name, user_group)
);
Now you have to create mysql user in a command line mysql prompt (to have information about mysql user creation please read the mysql documentatiion) or use phpmyadmin.
After the creation of your user we can start the configuration of the mysql authentification on apache configuration file.
This apache mysql authentification configuration is for a folder present on your folder but all website defined on this website need this mysql authentification
#vi /etc/httpd/conf.d/mod_authh_mysql.conf
<Directory /var/www>
AuthName "MySQL group authenticated zone"
AuthType Basic
AuthMYSQLEnable on
AuthMySQLUser mysql_user
AuthMySQLPassword mysql_pass
AuthMySQLDB mysql_db
AuthMySQLUserTable users
AuthMySQLNameField user_name
AuthMySQLPasswordField user_passwd
AuthMySQLGroupTable groups
AuthMySQLGroupField user_group
require group user
</Directory>
But you have a another choice to create a mysql authentification for a specifique website is to implement the mysql authentification on a VirtualHost section:
This configuration applied a mysql authentification on the admin folder present in your documentroot folder
#vi /etc/httpd/conf.d/vhost.conf
<VirtualHost>
....
<Location /admin>
AuthMYSQLEnable on
AuthMySQLUser mysql_user
AuthMySQLPassword mysql_pass
AuthMySQLDB mysql_db
AuthMySQLUserTable users
AuthMySQLNameField user_name
AuthMySQLPasswordField user_passwd
AuthMySQLGroupTable groups
AuthMySQLGroupField user_group
AuthName "MySQL group authenticated zone"
AuthType Basic
require valid-user
require group user
</Location>
<VirtualHost>
If you want to define your own condition for mysql authentification you have to add this option : AuthMySQLUserCondition
Example :
<VirtualHost>
....
<Location /admin>
AuthMYSQLEnable on
AuthMySQLUser mysql_user
AuthMySQLPassword mysql_pass
AuthMySQLDB mysql_db
AuthMySQLUserTable "user_info, user_status"
AuthMySQLUserCondition "user_info.user_name = user_status.user_name and user_status.status = 'OK')"
AuthName "MySQL Condition authenticated zone"
AuthType Basic
require valid-user
</Location>
<VirtualHost>
















































