• Home
  • About Us
  • Contact
  • Privacy Policy

LinuxAdmin.io

  • Home
  • Tutorials
    • System Administration
    • Linux Tutorials
    • Web Hosting
    • WordPress
    • Virtualization
    • Troubleshooting
    • OpenStack

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

 

 

Aug 17, 2017LinuxAdmin.io
2 1 vote
Article Rating
How To Use Percona Xtrabackup To Create A MySQL SlaveHow To Reset A MySQL Root Password
You Might Also Like
 
Reset a WordPress Password with MySQL
 
Mod_Expires Configuration In Apache
Subscribe
Notify of
guest
guest
6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Horst
Horst
5 years ago

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)

-2
Reply
LinuxAdmin.io
Author
LinuxAdmin.io
5 years ago
Reply to  Horst

Thank you for the tip!

0
Reply
Rob C
Rob C
4 years ago

Thanks! You’re a lifesaver. My passwords are MD5 encrypted and mod_authn_dbd won’t work.

0
Reply
LinuxAdmin.io
Author
LinuxAdmin.io
4 years ago
Reply to  Rob C

Glad to hear it worked out for you!

0
Reply
steve.zhougs
steve.zhougs
3 years ago

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

0
Reply
LinuxAdmin.io
Author
LinuxAdmin.io
3 years ago
Reply to  steve.zhougs

What version of mysql do you have installed?

0
Reply
5 years ago 6 Comments Apache, Web Hosting 6,073
Recent Posts
  • Laravel Installation Guide For CentOS
  • Openstack Services Explanation And Overview
  • OSSEC Intrusion Detection Installation On Centos 7
  • Configure ProFTPd for SFTP on CentOS
  • How To Check And Repair MyISAM Tables In MySQL
Most Commented
Hot Clone Linux Server with Rsync
Hot Clone A CentOS Server With Rsync
14 Comments
ngx_cache_purge module
Install The ngx_cache_purge Module In Nginx
8 Comments
piwik-nginx
Piwik Analytics on Nginx
8 Comments
Tags
linuxcentosLinux Performance Tuningsysadminkvmnetworkingmemcachedanalyticssystemd
About

We love Linux and are dedicated to creating Linux administration tutorials for System Administrators since 2016.

Most Viewed
Default Gateway
How To Configure A Default Gateway on CentOS
62,978 views
Zend Opcache
Setup and Optimize Zend OpCache
46,714 views
Install ffmpeg
FFMpeg Install On CentOS 7
20,909 views
Archives
Email subscription

Sign up for our newsletter to receive the latest news and event postings.

2018 © LinuxAdmin.io
wpDiscuz