Compiling PHP on CentOS 5 (64bit) with MySQL Support

If you try to build PHP 5.x.x on a 64bit CentOS install you may get this error:

checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... /var/lib/mysql/mysql.sock
checking for mysql_close in -lmysqlclient... no
checking for mysql_error in -lmysqlclient... no
configure: error: mysql configure failed. Please check config.log for more information.

Looking further into the config.log you will also see:

configure:60376: checking for mysql_error in -lmysqlclient
configure:60395: gcc -o conftest -I/usr/include -g -O2  -Wl,-rpath,/usr/lib/mysql -L/usr/lib/mysql -L/usr/lib  -Wl,-rpath,/usr/kerberos/lib64 -L/usr/kerberos/lib64 -Wl,-rpath,/usr -L/usr conftest.c -lmysqlclient  -lz -lpng -lz -lcurl -lz -lrt -lresolv -lm -ldl -lnsl  -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lcurl -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lidn -lssl -lcrypto -lz -lxml2 -lz -lm 1>&5
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.so when searching for -lmysqlclient
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.a when searching for -lmysqlclient
/usr/bin/ld: cannot find -lmysqlclient
collect2: ld returned 1 exit status

First things first, if you installed MySQL using yum you should make sure that you have the mysql-devel rpms installed. You can ensure they are installed by running the following command:

yum install mysql-devel

Once you've ensured that the mysql-devel rpms are installed you need to tell PHP where it should also look for additional libraries. We will pass the following to the configure script:

./configure --with-libdir=lib64 --with-mysql

That's it, from there you can continue on with the normal build.