Fix mod_auth_mysql on Ubuntu 64-bit

Posted on Sep 13 2009 in Web Development

At least twice, now, I've encountered problems (read: apache segfaults, oh noes!) with mod_auth_mysql on Ubuntu 64-bit installs, most recently using Jaunty Jackalope (9.04) -- the most recent release (at least until 9.10 comes out soon). In searching for solutions, I discovered that this issue has been reported at least a couple times, the issue has been identified (and is a super-simple fix), and a working patch exists... but as of the writing of this article, the fix has not yet been compiled into the repo packages.

So then this becomes one of those relatively rare times that I will compile my own package. I prefer to compile binary packages (deb files) rather than simply compiling from source and doing a "make install," since packages leverage the package management system for things like dependencies and upgrades. For instance, if Ubuntu does release the fix in the next version of mod_auth_mysql, I want to be able to seemlessly upgrade to the next version.

I'm going to describe the steps to fix mod_auth_mysql 4.3.9-11, but this general process should work for applying community patches and building deb files in general.

  1. Uninstall mod_auth_mysql:

    $ sudo apt-get remove libapache2-mod-auth-mysql
    
  2. Get mod_auth_mysql source (drops it in the current directory, so be where you want it, such as ~/src):

    $ sudo apt-get source libapache2-mod-auth-mysql
    
  3. Get dependencies for building from source:

    $ sudo apt-get build-dep libapache2-mod-auth-mysql
    
  4. Get a dependencies that didn't install with build-dep:

    $ sudo apt-get install apache2-threaded-dev
    

    (could be different for your system)

  5. Get devscripts package to make this all much easier:

    $ sudo apt-get install devscripts
    

    (installs postfix -- annoying)

  6. Set file perms on the source files you downloaded:

    $ sudo chown -R josh:josh *
    
  7. Enter src dir:

    $ cd mod-auth-mysql-4.3.9
    
  8. Prepare to apply patch. This actually starts a new shell with the current directory containing a copy of the code so you can edit it.

    $ dpatch-edit-patch -a fix_segfaults
    
  9. Apply patch, a one-line edit to mod_auth-mysql.c described here.

  10. Exit the shell.

  11. Add fix_segfaults to the end of debian/patches/00list.

  12. Record the changes and change the package version info. Change the version at the top of the file. I usually just add something at the end of the existing version string.

    $ dch -i
    
  13. Build the deb file. This will compile the source, package the binaries, and put the deb file one directory up.

    $ dpkg-buildpackage -rfakeroot
    
  14. Install the new package. Note: Your deb file name will be different based on how you changed the version string above.

    $ sudo dpkg -i ../libapache2_mod_auth_mysql-4.3.9-11_amd64.deb
    

Seems like a lot, but after you do it, it doesn't seem too bad, and you can bask in the glory of creating your own package -- which is reusable on all same-type systems.