RHEL5 上的 mod_auth_mysql

以前写过关于 mod_auth_mysql 的文章,新系统上马了 Cacti 和 Awstats 想到用认证机制保护起来,就想到了那篇文章。但是去 SourceForge 下载的 3.0.0 版本在 RHEL5 上安装时,报错: /…/build/libtool –silent –mode=compile gcc -prefer-pic?? -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -g -O2 -pthread -I/opt/…/include? -I/opt/…/include?? -I/opt/…/include? -I/usr/include/mysql? -c -o mod_auth_mysql.lo mod_auth_mysql.c && touch mod_auth_mysql.slo
mod_auth_mysql.c:591: error: expected expression before ‘mysql_auth_config_rec’
mod_auth_mysql.c:591: error: initializer element is not constant
mod_auth_mysql.c:591: error: (near initialization for ‘mysql_auth_cmds[0].cmd_data’)
mod_auth_mysql.c:593: error: expected expression before ‘mysql_auth_config_rec’
后来找到原来 RHEL5 提供了这个软件的 RPM 包 mod_auth_mysql-3.0.0-3.1 ,安装以后,配置起来十分的省力:

在对应的目录下添加 .htaccess 文件如下:

AuthBasicAuthoritative Off
AuthUserFile /dev/null
# AuthGroupFile /dev/null

Authname “Test Awstats”
Authtype Basic
# Require user user1 user2

# Define Authorisation type

AuthMySQLHost localhost
# AuthMySQLPort
AuthMySQLDB mydb
AuthMySQLUser db_username
AuthMySQLPassword db_connectPass
AuthMySQLSocket /tmp/mysql.sock
# crypt: UNIX crypt() encryption
# scrambled: MySQL PASSWORD encryption
# md5: MD5 hashing
# aes: Advanced Encryption Standard (AES) encryption

## AuthMySQLPwEncryption none | crypt | scrambled | md5 | aes | sha1

AuthMySQLPwEncryption md5
AuthMySQLEnable On
AuthMySQLUserTable user_auth
AuthMySQLNameField username
AuthMySQLPasswordField password
# AuthMySQLGroupTable cdb_usergroups
# AuthMySQLGroupField grouptitle

##AuthMySQLUserCondition
# AuthMySQLNoPasswd Off

# AuthMySQLSaltField <>
###AuthMySQLGroupCondition
##AuthMySQLKeepAlive Off
# AuthMySQLAuthoritative On
##AuthMySQLCharacterSet

Require valid-user

重启 httpd 检验。
这样在 Apache 2.2.8 上配置 mod_auth_mysql 3.0.0 就算成功了!