{"id":1293,"date":"2010-02-09T16:41:19","date_gmt":"2010-02-09T08:41:19","guid":{"rendered":"http:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/?p=1293"},"modified":"2011-01-03T09:06:12","modified_gmt":"2011-01-03T01:06:12","slug":"configure-mod_auth_mysql-on-self-compiled-apache-2-2-x","status":"publish","type":"post","link":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/?p=1293","title":{"rendered":"configure mod_auth_mysql on self-compiled Apache 2.2.x"},"content":{"rendered":"<p>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&#8217;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.<\/p>\n<p>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&#8217;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&#8217;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.<\/p>\n<p>Afterward, I use the below .htaccess to test according to the doc:<\/p>\n<p><!-- .style1 { \tfont-family: \"Courier New\", Courier, monospace; \tfont-size: 10px; } --><\/p>\n<p class=\"style1\">Options Indexes<br \/>\nAuthName &#8220;Pls enter your username &amp; password&#8221;<br \/>\nAuthType Basic<br \/>\nAuthMYSQLEnable on<br \/>\nAuthMySQLHost [mysqlhost]<br \/>\nAuthMySQLUser [mysql_user]<br \/>\nAuthMySQLPassword [myql_pass]<br \/>\nAuthMySQLDB [database]<br \/>\nAuthMySQLUserTable user_auth<br \/>\nAuthMySQLNameField user_name<br \/>\nAuthMySQLPasswordField user_passwd<br \/>\nAuthMySQLPwEncryption md5<br \/>\nrequire valid-use<\/p>\n<p>But I got the errors below :<\/p>\n<p class=\"style1\">[Mon Feb 08 11:58:06 2010] [error] Internal error: pcfg_openfile() called with NULL filename<br \/>\n[Mon Feb 08 11:58:06 2010] [error] [client x.x.x.x] (9)Bad file descriptor: Could not open password file: (null)<\/p>\n<p>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 :<\/p>\n<p class=\"style1\">Options Indexes<br \/>\nAuthName &#8220;Pls enter your username &amp; password&#8221;<br \/>\nAuthType Basic<br \/>\nAuthBasicAuthoritative Off<br \/>\nAuthUserFile \/dev\/null<\/p>\n<p>AuthMYSQLEnable on<br \/>\nAuthMySQLHost [mysqlhost]<br \/>\nAuthMySQLUser [mysql_user]<br \/>\nAuthMySQLPassword [myql_pass]<br \/>\nAuthMySQLDB [database]<br \/>\nAuthMySQLUserTable user_auth<br \/>\nAuthMySQLNameField user_name<br \/>\nAuthMySQLPasswordField user_passwd<br \/>\nAuthMySQLPwEncryption md5<br \/>\nrequire valid-use<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t use the traditional file based authentication (password hard-coded [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[3],"tags":[20],"class_list":["post-1293","post","type-post","status-publish","format-standard","hentry","category-computer","tag-apache","odd"],"_links":{"self":[{"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1293"}],"version-history":[{"count":33,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1293\/revisions"}],"predecessor-version":[{"id":2004,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1293\/revisions\/2004"}],"wp:attachment":[{"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staff.ie.cuhk.edu.hk\/~sfluk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}