GenerationIP

Just for you

  • Increase font size
  • Default font size
  • Decrease font size
Home Documentation Mini Howto HowTo install mod_auth_mysql for apache

HowTo install mod_auth_mysql for apache

E-mail Print PDF
User Rating: / 3
PoorBest 

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

INSTALLATION

#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.

CONFIGURATION

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>

TIPS

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>

Last Updated on Saturday, 30 January 2010 22:31  

Share this article:

Add to: Mr. Wong Add to: Webnews Add to: Icio Add to: Oneview Add to: Kledy.de Social Bookmarking Add to:  FAV!T Social Bookmarking Add to: Favoriten.de Add to: Seekxl Add to: Social Bookmark Portal Add to: BoniTrust Add to: Power-Oldie Add to: Bookmarks.cc Add to: Newskick Add to: Newsider Add to: Linksilo Add to: Readster Add to: Yigg Add to: Linkarena Add to: Digg Add to: Del.icoi.us Add to: Reddit Add to: Jumptags Add to: Upchuckr Add to: Simpy Add to: StumbleUpon Add to: Slashdot Add to: Netscape Add to: Furl Add to: Yahoo Add to: Blogmarks Add to: Diigo Add to: Technorati Add to: Newsvine Add to: Blinkbits Add to: Ma.Gnolia Add to: Smarking Add to: Netvouz Add to: Folkd Add to: Spurl Add to: Google Add to: Blinklist Information