Compiling and Installing mod_auth_mysql on OS X 10.5.6

April 17th, 2009 by nils

The apche module mod_auth_mysql makes it possible to use a MySQL database instead of e.g. a passwd file. There is an installer of the module for Mac OS X 10.4, but no installation package or port for Mac OS X 10.5 or later. I played around with the sources a little bit and finally managed to get it to compile and apache to start without error messages. I’ve created a diff file to patch mod_auth_mysql.c. The following steps explain how to apply the patch, compile the module and test your apache configuration.

We’ll first create a src folder in your user directory, download mod_auth_mysql and expand it:

$ mkdir ~/src
$ cd ~/src
$ curl -O http://puzzle.dl.sourceforge.net/sourceforge/\
modauthmysql/mod_auth_mysql-3.0.0.tar.gz
$ tar zxvf mod_auth_mysql-3.0.0.tar.gz

Now you have the sources of the module in the folder mod_auth_mysql-3.0.0. Before we can compile it, the patch has to be applied. Here is the diff file mod_auth_mysql, save it to

~/src/mod_auth_mysql-3.0.0/mod_auth_mysql.diff

To apply the patch, we change to the sources directory and execute the unix patch program that takes the original file and applies the diff file as patch:

$ cd mod_auth_mysql-3.0.0
$ patch mod_auth_mysql.c mod_auth_mysql.diff

Now we are ready to compile the module, install it and add it to http.conf, the apache configuration file. Apache modules are compiled using apxs, the APache eXtenSion tool. Before we start, lets look at the command:

$ sudo apxs -c -i -a -D lmysqlclient -lm -lz \
-I/usr/local/mysql/include/mysql/\
-L/usr/local/mysql/lib/ -Wc,"-arch x86_64" \
-Wl,"-arch x86_64" mod_auth_mysql.c

We should execute apxs as super user because it will attempt to install the module to /usr/libexec/apache2/, so we prepend the command with sudo. the -c option tells apxs to compile the module, -i to install it and -a to add a line to http.conf, telling apache to load the module. The -I and -L options are used to provide information about where MySQL is installed and where to find the mysql.h file. I compiled and installed MySQL from source and installed it in the /usr/local/mysql/ directory, if your installation is in a different place, you might have to adjust these parameters. (An excellent guide on compiling and installing MySQL on OS X is available at http://hivelogic.com: “Installing MySQL on Mac OS X“)

When you execute the above command, you should see an output like this:

/usr/share/apr-1/build-1/libtool --silent --mode=compile gcc    -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp  -I/usr/include/apache2  -I/usr/include/apr-1   -I/usr/include/apr-1  -arch x86_64 -I/usr/local/mysql/include/mysql/ -Dlmysqlclient  -c -o mod_auth_mysql.lo mod_auth_mysql.c && touch mod_auth_mysql.slo
/usr/share/apr-1/build-1/libtool --silent --mode=link gcc -o mod_auth_mysql.la -arch x86_64  -L/usr/local/mysql/lib/ -lm -lz -rpath /usr/libexec/apache2 -module -avoid-version    mod_auth_mysql.lo
/usr/share/httpd/build/instdso.sh SH_LIBTOOL='/usr/share/apr-1/build-1/libtool' mod_auth_mysql.la /usr/libexec/apache2
/usr/share/apr-1/build-1/libtool --mode=install cp mod_auth_mysql.la /usr/libexec/apache2/
cp .libs/mod_auth_mysql.so /usr/libexec/apache2/mod_auth_mysql.so
cp .libs/mod_auth_mysql.lai /usr/libexec/apache2/mod_auth_mysql.la
cp .libs/mod_auth_mysql.a /usr/libexec/apache2/mod_auth_mysql.a
ranlib /usr/libexec/apache2/mod_auth_mysql.a
chmod 644 /usr/libexec/apache2/mod_auth_mysql.a
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/libexec/apache2

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
     during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/libexec/apache2/mod_auth_mysql.so
[activating module `mysql_auth' in /private/etc/apache2/httpd.conf]

If there are no error messages, you can test the apache configuration with apachectl:

$ apachectl configtest

If the output is

Syntax OK

you can continue by restarting apache:

$ sudo apachectl graceful

The next step would be to set up your locations in http.conf, but that’s for another time…

7 Comments

  1. A nice post that almost worked for me. I end up getting this message on the final step.

    apachectl configtest
    httpd: Syntax error on line 116 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/mod_auth_mysql.so into server: dlopen(/usr/libexec/apache2/mod_auth_mysql.so, 10): Symbol not found: _make_scrambled_password\n Referenced from: /usr/libexec/apache2/mod_auth_mysql.so\n Expected in: dynamic lookup\n

    My guess is there is a linking problem with MySql because the 64 bit compilation. Any ideas?

    Comment by Herb Payerl — September 14, 2009 @ 1:31 am

  2. @Herb: Which OS X version are you using?

    Comment by nils — September 21, 2009 @ 4:11 pm

  3. Fantastic post, it worked for me on 10.5.8. Thanks for the legwork!

    Comment by michal — January 22, 2010 @ 10:27 pm

  4. localhost:~ jaxchow$ apachectl configtest
    httpd: Syntax error on line 489 of /private/etc/apache2/httpd.conf: Syntax error on line 3 of /private/etc/apache2/other/httpd-mysql.conf: Cannot load /usr/libexec/apache2/mod_auth_mysql.so into server: dlopen(/usr/libexec/apache2/mod_auth_mysql.so, 10): Symbol not found: _make_scrambled_password\n Referenced from: /usr/libexec/apache2/mod_auth_mysql.so\n Expected in: dynamic lookup\n

    why?

    Comment by jaxchow — March 8, 2010 @ 11:35 am

  5. I also get the Symbol not found error, has anyone got this working on 10.6?

    Comment by 4nd — May 5, 2010 @ 7:54 pm

  6. Hi Andy, sorry, can’t help you there. I’ve only tried this on 10.5.x.

    Good luck and let us know if you get it to work,
    Nils

    Comment by nils — May 5, 2010 @ 9:11 pm

  7. After running the sudo xarg command I get the following error. Do you know why?

    FYI: This path doesn’t exist on my computer “/usr/include/apache2″ not sure why it’s outputted. I’m guessing this is why the command errors out. Any help is appreciated.

    /usr/share/apr-1/build-1/libtool –silent –mode=compile gcc -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -I/usr/local/include -I/usr/include/apache2 -I/usr/include/apr-1 -I/usr/include/apr-1 -arch x86_64 -I/usr/local/mysql/include/mysql/-L/usr/local/mysql/lib/ -Dlmysqlclient -c -o mod_auth_mysql.lo mod_auth_mysql.c && touch mod_auth_mysql.slo
    env: gcc: No such file or directory
    apxs:Error: Command failed with rc=65536
    .

    Comment by Ryan — August 15, 2011 @ 3:23 am

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.