首先是区别。
mod_authn_dbd http://httpd.apache.org/docs/2.2/mod/mod_authn_dbd.html提供身份验证前端,例如 mod_auth_digest 和 mod_auth_basic,通过在 SQL 表中查找用户来对用户进行身份验证。
mod_auth_mysql https://sourceforge.net/projects/modauthmysql/是一个 Apache 模块,允许使用存储在 MySQL 数据库中的用户和组数据进行身份验证。该项目似乎自 2005 年以来就没有更新过,所以我会选择mod_authn_dbd http://httpd.apache.org/docs/2.2/mod/mod_authn_dbd.html.
要正确设置,首先您需要在 apache 配置中正确配置 mod_authn_dbd 和 mod_dbd,mod_dbd 负责您的数据库连接。完成此操作后(确保您的 Apache 正在运行且这些模块处于活动状态),您就可以继续配置它们。
将类似的内容添加到您的 apache 配置中以配置数据库连接:
<IfModule mod_dbd.c>
DBDriver mysql
DBDParams "host=(your_db_server, p.e. 127.0.0.1) dbname=your_db_name user=your_db_user pass=your_db_pass"
DBDMin 1
DBDKeep 8
DBDMax 20
DBDExptime 200
</IfModule>
现在将您所需的身份验证配置添加到 apache 配置中:
<Directory "/your/svn/repository/path/">
Options FollowSymLinks Indexes MultiViews
AuthType Basic
AuthName "Allowed users Only"
AuthBasicProvider dbd
AuthDBDUserPWQuery "SELECT pwd FROM tbl_users, tbl_user_group WHERE tbl_users.user_id=%s AND tbl_user.user_id=tbl_user_group.user_id"
Require valid-user
AllowOverride None
Order allow,deny
Allow from all
</Directory>
我简化了 SELECT 语句以获得更好的可读性,您必须扩展它才能完善您的配置。
EDIT:
输入后,我在网上找到了一个非常好的示例,也许可以阅读它here http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Apache/A_3270-Enabling-and-Administering-Apache%27s-HTTPD-authn-dbd-MySQL-authentication-through-PHP-on-Suse.html, 也。它比我的简化答案要深入得多。