Ubuntu, apache2 and mod_auth_mysql

I’ve been moving a site I built for a client quite a while ago over to a new server. The old server had been using versions of apache 1.3.x and mod_auth_mysql compiled from source, while the new server is running apache 2.x installed from Ubuntu’s packages. Most of the migration has gone pretty smoothly thus far, considering how different the versions of software are on the new server.

One difference that had me stuck for a while was getting mod_auth_mysql to authenticate users against the database on the new server. I was able to install it as a package instead of compiling from source, and the new version seemed to use the same configuration directives as the old one, but I was getting 500 errors whenever I accessed a password protected page. The web server log was reporting

Internal error: pcfg_openfile() called with NULL filename
[client 10.1.1.99] (9)Bad file descriptor: Could not open password file: (null)

Additionally, the database server wasn’t logging any connections from the web server. I finally came across this thread which explains the issue. Apparently, apache2 wants to use the htpasswd file facilities to authenticate users, unless you explicitly tell it not to. Adding

AuthBasicAuthoritative Off

to the .htaccess files allows mod_auth_mysql to perform authentications. That was a step in the right direction, however apache was still recording errors whenever a password protected page was requested. This seems to be another side effect of apache2 wanting to use htpasswd files. If you add

AuthUserFile /dev/null

to the .htaccess file as well, it stops complaining.

2 Responses to “Ubuntu, apache2 and mod_auth_mysql”

  1. Bob Dole says:

    THANK YOU VERY MUCH!!!!

    I have been struggling with this most of the morning and into the afternoon.
    After looking through all the guides and Howtos I have seen no mention of what you have posted here, I sometimes wonder if the guys writing those docs have ever gotten the stuff to work or not.

  2. cosco says:

    Thanks a lot.
    That solved my problem. apache was complaining “user xxx not found:” in /var/log/apache2/error.log
    Now all works fine.

Leave a Reply