Search code examples
phplinuxcompilationmysql-connector

Compile PHP 5.2 with an older libmysqlclient


I have a server with a newer libmysqlclient under Rocky Linux 8. For legacy purposes it needs to have PHP 5.2 compiled. My PHP 5.2 is patched for openssl 1.1. It compiles just fine when using the OS installed libmysqlclient, but PHP scripts running PHP 5.2 fail when trying to negotiate with the newer Client API version => 8.0.32 (Malformed packet, etc. errors). I am trying to compile PHP 5.2 from source with --with-mysql='/usr/local/mysql_old' '--with-libdir=lib64' (along with other extensions). I downloaded a MySQL community server 5.5 tar.gz from the MySQL archives and copied the libraries and include folder to /usr/local/mysql_old retaining the structure:

drwxr-xr-x  3 root root     4096 Oct 17 15:20 ./
drwxr-xr-x 50 root root     4096 Oct 17 16:34 ../
drwxr-xr-x  3 root root     4096 Oct 17 13:20 include/
-rw-r--r--  1 root root 14850536 Oct 17 15:12 libmysqlclient.a
-rw-r--r--  1 root root 14850536 Oct 17 15:12 libmysqlclient_r.a
lrwxrwxrwx  1 root root       26 Oct 17 15:20 libmysqlclient_r.so -> libmysqlclient_r.so.18.0.0*
lrwxrwxrwx  1 root root       26 Oct 17 15:20 libmysqlclient_r.so.18 -> libmysqlclient_r.so.18.0.0*
-rwxr-xr-x  1 root root  6935608 Oct 17 15:12 libmysqlclient_r.so.18.0.0*
lrwxrwxrwx  1 root root       24 Oct 17 15:20 libmysqlclient.so -> libmysqlclient.so.18.0.0*
lrwxrwxrwx  1 root root       24 Oct 17 15:20 libmysqlclient.so.18 -> libmysqlclient.so.18.0.0*
-rwxr-xr-x  1 root root  6935608 Oct 17 15:12 libmysqlclient.so.18.0.0*

then I tried:

export LDFLAGS="-L/usr/local/mysql_old"
export LD_LIBRARY_PATH="/usr/local/mysql_old:$LD_LIBRARY_PATH"
export CFLAGS="-I/usr/local/mysql_old/include"
export CPPFLAGS="-I/usr/local/mysql_old/include"

then configure always fails with

configure: error: Cannot find libmysqlclient under /usr/local/mysql_old.
Note that the MySQL client library is not bundled anymore!

Any suggestions on how to get the configure script to use the old libmysqlclient?


Solution

  • It turned out to be pretty trivial. A strace showed

    openat(AT_FDCWD, "/usr/local/mysql_old/lib64/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
    openat(AT_FDCWD, "/usr/local/mysql_old/lib64/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
    faccessat(AT_FDCWD, "/usr/local/mysql_old/lib64/libmysqlclient.*", R_OK) = -1 ENOENT (No such file or directory)
    

    so seeing as how I am compiling --with-libdir=lib64 I decided to move the libraries to /usr/local/mysql_old/lib64 and it configured/compiled successfully.