ubuntu apache2 mod_auth_mysql配置

来源:互联网 发布:淘宝店铺权重如何提升 编辑:程序博客网 时间:2024/06/02 17:03

 转自: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
  1. patch -p0 < apache22.diff  

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

[cpp] view plaincopy
  1. locate libmysqlclient.so  
我机器的地址是:/usr/lib/i386-linux-gnu/

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

[cpp] view plaincopy
  1. apxs2 -c -L/usr/lib/i386-linux-gnu/ -I/usr/include/mysql -lmysqlclient -lm -lz mod_auth_mysql.c  

如果提示为找到apxs2,则在终端下输入以安装缺少的文件:
[cpp] view plaincopy
  1. sudo apt-get install apache2-dev  
然后再运行编译的命令,如果提示找不到mysql.h文件,则需要安装:
[cpp] view plaincopy
  1. sudo apt-get install libmysqlclient15-dev  

然后再运行:
[cpp] view plaincopy
  1. 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
  1. 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
  1. cd /etc/apache2/mods-enabled   
  2. ln -s ../mods-available/auth_mysql.load   

然后查看/etc/apache2/mods-enabled中auth_mysql.load文件的内容是否如下所示:
[cpp] view plaincopy
  1. LoadModule mysql_auth_module /usr/lib/apache2/modules/mod_auth_mysql.so  

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


3.写.htaccess配置文件

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

.htaccess文件内容如下:

[cpp] view plaincopy
  1. ErrorDocument 401 /Chapter17/rejection.html  
  2.   
  3. AuthName "Personnel Only "  
  4. AuthType Basic  
  5.   
  6.   
  7. AuthUserFile /dev/null  
  8. AuthMySQLEnable On  
  9. <strong><span style="color:#FF0000;">AuthBasicAuthoritative Off</span></strong>  
  10. AuthMySQLHost localhost  
  11. AuthMySQLUser webauth  
  12. AuthMySQLPassword webauth  
  13. AuthMySQLDB auth  
  14. AuthMySQLUserTable authorised_users  
  15. AuthMySQLNameField name  
  16. AuthMySQLPasswordField password  
  17. AuthMySQLAuthoritative On  
  18. AuthMySQLPwEncryption none  
  19.   
  20. 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的配置。
0 0