您的位置:首页 > 运维架构 > Apache

ubuntu apache2 mod_auth_mysql配置

2015-11-09 16:25 507 查看
转自:http://blog.csdn.net/looong2b/article/details/8539884



前提:ubuntu12.04已安装配置好apache和mysql,详情请见:http://blog.csdn.net/looong2b/article/details/8504614

mod_auth_mysql-3.0.0下载地址:http://sourceforge.net/projects/modauthmysql/

1.编译mod_auth_mysql.c

下载mod_auth_mysql-3.0.0后解压后得到mod_auth_mysql-3.0.0文件夹,文件夹中有mod_auth_mysql.c文件。

下载apache22.diff文件并拷到mod_auth_mysql-3.0.0文件夹下,

下载地址为:http://sourceforge.net/tracker/download.php?group_id=60218&atid=493464&file_id=168517&aid=1437139

终端下进入mod_auth_mysql-3.0.0文件夹,输入如下内容打apache22.diff补丁:

[cpp]
view plaincopy

patch -p0 < apache22.diff

终端下输入如下内容确定自己的libmysqlclient.so.xx的位置(xx为一个数字):

[cpp]
view plaincopy

locate libmysqlclient.so

我机器的地址是:/usr/lib/i386-linux-gnu/

然后在终端输入如下命令进行编译:

[cpp]
view plaincopy

apxs2 -c -L/usr/lib/i386-linux-gnu/ -I/usr/include/mysql -lmysqlclient -lm -lz mod_auth_mysql.c

如果提示为找到apxs2,则在终端下输入以安装缺少的文件:

[cpp]
view plaincopy

sudo apt-get install apache2-dev

然后再运行编译的命令,如果提示找不到mysql.h文件,则需要安装:

[cpp]
view plaincopy

sudo apt-get install libmysqlclient15-dev

然后再运行:

[cpp]
view plaincopy

apxs2 -c -L/usr/lib/i386-linux-gnu/ -I/usr/include/mysql -lmysqlclient -lm -lz mod_auth_mysql.c

编译完成后在文件夹内会有mod_auth_mysql.la文件生成,在终端下运行命令:

[cpp]
view plaincopy

sudo apxs2 -i mod_auth_mysql.la

完成后终端会提示“Libraries have been installed in:

/usr/lib/apache2/modules”

这样mod_auth_mysql就编译成功了。

2.配置apache

在终端下运行如下命令以激活mod_auth_mysql模块

[cpp]
view plaincopy

cd /etc/apache2/mods-enabled
ln -s ../mods-available/auth_mysql.load

然后查看/etc/apache2/mods-enabled中auth_mysql.load文件的内容是否如下所示:

[cpp]
view plaincopy

LoadModule mysql_auth_module /usr/lib/apache2/modules/mod_auth_mysql.so

如果不是,请改为这个路径。

3.写.htaccess配置文件

在你想保护的文件夹下创建一个.htaccess文件,我想保护的文件路径是/var/www/Chapter17

.htaccess文件内容如下:

[cpp]
view plaincopy

ErrorDocument 401 /Chapter17/rejection.html

AuthName "Personnel Only "
AuthType Basic

AuthUserFile /dev/null
AuthMySQLEnable On
<strong><span style="color:#FF0000;">AuthBasicAuthoritative Off</span></strong>
AuthMySQLHost localhost
AuthMySQLUser webauth
AuthMySQLPassword webauth
AuthMySQLDB auth
AuthMySQLUserTable authorised_users
AuthMySQLNameField name
AuthMySQLPasswordField password
AuthMySQLAuthoritative On
AuthMySQLPwEncryption none

require valid-user

每个配置项的意义可以查看mod_auth_mysql-3.0.0文件夹中的CONFIGURE文件。
注意:AuthBasicAuthoritative Off 这项配置一定要有,不然即使输入数据库中正确的用户名和密码也不能成功登录,/var/log/apache2/error.log中会报错:user XXX not found(XXX为你输入的用户名)

这样就完成了ubuntu下apache2 mod_auth_mysql的配置。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: