X

How To Install And Configure mod_auth_mysql On Apache

What Is Mod_Auth_Mysql?

mod_auth_mysql is an Apache module used for authenticating users against a MySQL database. It is commonly used to protect items on a website via a user login prompt. The module is able to authenticate against a  MySQL database to check for a valid username and password, it supports various encryption methods. 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 the module was 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.

 

 

LinuxAdmin.io
3.5 2 votes
Article Rating
LinuxAdmin.io:

View Comments (6)

  • When you're using MariaDB on CentOS7 you have to create a symlink for mysqlclient.so. Otherwise the module won't compile.
    (ln -s /usr/lib64/mysql/libmysqlclient.so.20.3.8 /usr/lib64/libmysqlclient.so)

  • I got an error.
    httpd: Syntax error on line 146 of /etc/httpd/httpd.conf: Cannot load modules/mod_auth_mysql.so into server: /usr/local/apache2/modules/mod_auth_mysql.so: undefined symbol: make_scrambled_password

Related Post