You are here
Home > Web Hosting > Apache > How To Install And Configure mod_auth_mysql On Apache

How To Install And Configure mod_auth_mysql On Apache

How to install mod_auth_mysql

What Is Mod_Auth_Mysql?

mod_auth_mysql is a Apache module used for authenticating users against a MySQL database. It is commonly used to protect pages and directories accessed via a web browser. You can view more about it on the project page.


This guide assumes you already have a working mysql installation and Apache is already installed.  If you do not have Apache installed please see our guide on How To Install Apache

Install mod_auth_mysql

The last version of mod_auth_mysql created was designed for Apache 2.0 (we will show you how to patch it for 2.2 and 2.4 as well) First change to a download directory

cd /usr/src

Get the package

wget https://github.com/linuxadminio/mod_auth_mysql/raw/master/mod_auth_mysql-3.0.0.tar.gz

Extract the package

tar xfvz mod_auth_mysql-3.0.0.tar.gz

Go into the directory

cd mod_auth_mysql-3.0.0

If you only have Apache 2.0 you can skip the next few steps, if you have 2.2 or 2.4 get the patch

https://raw.githubusercontent.com/linuxadminio/mod_auth_mysql/master/mod_auth_mysql-300-apache-22.patch

Patch mod_auth_mysql for Apache 2.2

patch < mod_auth_mysql-300-apache-22.patch

If you have Apache 2.4, you will need to perform one more step. Open up mod_auth_mysql.c

nano mod_auth_mysql.c

Change the following lines

line 908 from

return r->connection->remote_ip;

To

return r->connection->client_ip;

Line 1273  from:

const apr_array_header_t *reqs_arr = ap_requires(r);

To:

const apr_array_header_t *reqs_arr = NULL;

Line 1275 from:

const array_header *reqs_arr = ap_requires(r);

To:

const array_header *reqs_arr = NULL;

Go ahead and compile it

apxs -c -L/usr/lib/mysql -I/usr/include/mysql -lmysqlclient -lm -lz mod_auth_mysql.c

You should now be able to load the module in your httpd.conf

nano /etc/httpd/conf/httpd.conf

and add the following line

LoadModule mysql_auth_module modules/mod_auth_mysql.so

Go ahead and restart apache

service httpd restart

It should restart successfully and you should be able to use mod_auth_mysql to authenticate now.

 

 

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz
Top