How to , and other stuff about linux, photo, php … A linux, photography blog. To remember some linux situation, and fix them quickly.

March 31, 2008

mod_auth_mysql Apache with cPanel

Filed under: Linux — Tags: , , — admin @ 2:18 pm

Overview:
mod_auth_mysql is an Apache module that allows authentication using user and group data stored in MySQL databases. Originally by Vivek Khera for Apache1, now also includes a version for Apache 2. Official SourceForge Project website http://sourceforge.net/projects/modauthmysql/

This tutorial will cover installing mod_auth_mysql on Apache for cPanel/WHM web servers. It was tested on Red Hat Enterprise with PHP 4.3.10 running Apache/1.3.33 with MySQL 4.0.20-standard using mod_auth_mysql-2.9.0

Installing mod_auth_mysql on Apache
The good news is that you don’t need to recompile Apache manually to install this addon! Simply follow the steps for an easy installation that takes about 15-25 minutes.

First off you’ll need to grab a copy of the latest mod_auth_mysql files
Download mod_auth_mysql-2.9.0.tar.gz

Now that you have the source file you will need to upload it to your web server. Connect to your server by FTP and upload the file to a directory; it doesn’t matter where it goes we’ll move it in a minute.

Now login as root to your server through SSH and go to the directory where you uploaded the file. Move the file to another location.

mv mod_auth_mysql-2.9.0.tar.tar /usr/local/src/mod_auth_mysql-2.9.0.tar.tar

Extract the files contents

tar xvzf mod_auth_mysql-2.9.0.tar.tar
cd mod_auth_mysql-2.9.0.tar.tar

Open and read the BUILD and CONFIGURE documents for a general install understanding.

Now we’ll build the module file.

/usr/local/apache/bin/apxs -c -lmysqlclient -lm -lz -I /usr/include/mysql/ mod_auth_mysql.c

After building the module we will install it.

/usr/local/apache/bin/apxs -i mod_auth_mysql.so

Open up httpd.conf with your favourite editor, we need to add two lines to the configuration.

pico /usr/local/apache/conf/httpd.conf
Search for the .so files and add this below them.
ctrl + w
and type in .so, press enter. You should see this with a list of modules

# Example
# LoadModule foo_module libexec/mod_foo.so

Scroll down to the last .so module listed and enter a new line.

LoadModule mysql_auth_module libexec/mod_auth_mysql.so

We need to add a second line to the httpd.conf so lets do another search.
Search for the AddModule files and add this below them.
ctrl + w
and type in AddModule, press enter. You should see this with a list of files with a .c extension. Scroll to the bottom of the list and add the following.

AddModule mod_auth_mysql.c

Save your Apache configuration changes.
ctrl + x then press Y

Now mod_auth_mysql has been installed but you want to test your Apache configuration first to ensure everything is ok! Run the apachectl configtest. The configtest will not affect your live server, so starting and stopping the configtest won’t stop and start your websites.

apachectl configtest start

You should see a message that says Syntax OK. This means Apache is ready to go.

Restart the live Apache server
/etc/init.d/httpd restart

You can see your new module in phpinfo(); pages, in the apache heading, you should see.

Loaded Modules mod_auth_mysql

You have successfully setup mod_auth_mysql on Apache.

The basic deal is to turn off MySQL authentication across the server, and then turn it on only for the diretories where it’s required.

In your httpd.conf file, look for this bit…

Options All
AllowOverride All

and change to

Options All
AuthMySQLEnable off
AllowOverride All

Then for each of the directories where you want MySQL authentication, either in httpd.conf or in an .htaccess file, add the line:

AuthMySQLEnable on

Originaly posted at:http://www.webhostgear.com

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress