Travel

Categories

configure mod_auth_mysql on self-compiled Apache 2.2.x

Recently I have a need to configure a web directory to have user authentication to access its content. The simplest way is to use .htaccess + htpasswd. However,the requirement specified that the user should be able to change their assigned password later. This requirement make me can’t use the traditional file based authentication (password hard-coded and cannot be changed by user). After some google search, I decided to use put the users and password in the MySQL database so the user can change their password easily through a simple PHP program.

In order to make use of the MySQL user authentication via Apache .htaccess, I have to compile the mod_auth_mysql module into the apache server. This seems to be easy at the first glance, however I can’t compile it successfully on the apache 2.2.x. It seems that the module is designed for the earlier 1.3.x version and can’t compile well on 2.2.x. However, I remembered I have installed this module as RPM on CentOS/RHEL 5 a no. of times so this module should be able to work well with Apache 2.2.x. At last I get the source RPM as mod_auth_mysql-3.0.0-3.1.src.rpm from CentOS repository, install it and patch the bundled tar.gz with the bundled patch and compile, it works.

Afterward, I use the below .htaccess to test according to the doc:

Options Indexes
AuthName “Pls enter your username & password”
AuthType Basic
AuthMYSQLEnable on
AuthMySQLHost [mysqlhost]
AuthMySQLUser [mysql_user]
AuthMySQLPassword [myql_pass]
AuthMySQLDB [database]
AuthMySQLUserTable user_auth
AuthMySQLNameField user_name
AuthMySQLPasswordField user_passwd
AuthMySQLPwEncryption md5
require valid-use

But I got the errors below :

[Mon Feb 08 11:58:06 2010] [error] Internal error: pcfg_openfile() called with NULL filename
[Mon Feb 08 11:58:06 2010] [error] [client x.x.x.x] (9)Bad file descriptor: Could not open password file: (null)

Again doing some research found that I have to turn off file based authentication explicilty, otherwise apache will try to find the password file and failed. The correct .htaccess should be as below :

Options Indexes
AuthName “Pls enter your username & password”
AuthType Basic
AuthBasicAuthoritative Off
AuthUserFile /dev/null

AuthMYSQLEnable on
AuthMySQLHost [mysqlhost]
AuthMySQLUser [mysql_user]
AuthMySQLPassword [myql_pass]
AuthMySQLDB [database]
AuthMySQLUserTable user_auth
AuthMySQLNameField user_name
AuthMySQLPasswordField user_passwd
AuthMySQLPwEncryption md5
require valid-use

2 comments to configure mod_auth_mysql on self-compiled Apache 2.2.x

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

WP-Highlight