Archive for June 22, 2007
Enable MySQLi Extension in PHP
In my previous blog, I talked about MySQL’s stored procedures and how MySQLi support must be enabled in PHP in order to utilize stored procedures. That also means a re-compilation of PHP is necessary.
To compile PHP with MySQLi support, you need to add this to PHP configure:
--with-mysqli[=location of mysql_client]
I always use the binary installs so “mysql_client” is in /usr/local/mysql/bin/. So in my case, the option looks like:
--with-mysqli=/usr/local/mysql/bin/mysql_config
Do a search on that file if you are not sure where it is on your system. Also, make sure the one you found has the same version as the the version of MySQL installed. You can see the version by running:
mysql_client --version
If you are lucky, that is all you need to do to enable MySQLi support. However, if the configure stops with the message, you have a problem:
configure: error: wrong mysql library version or lib not found. Check config.log for more information
Don’t worry. There are two options here. First option is to upgrade MySQL to the latest version which is 5.0.41 (at the time of this writing). 5.0.41 includes the necessary shared library files for PHP to compile for MySQLi support. I am not sure about at what point did MySQL decide to include the files (I know for sure they weren’t in at least versions before 5.0.27). They are probably going to include the files from this point onward.
Second option is to compile the shared libraries yourself. If that is what you decided to do, please read on.
Next, go on to MySQL’s website and download the source corresponding to the version you have on your system. You may need to look into the Archive section if yours isn’t the most up-to-date.
Once you have grabbed the source tar file, do:
tar zxvf mysql-5.x.xx.tar.gz cd mysql-5.x.xx ./configure --enable-shared make
You do not need make install since we will keep the binaries we have installed. All what we are doing is to make libmysqlclient.so (shared object) available for PHP to link to.
After make, do:
cd libmysql/.libs cp libmysqlclient.so.15.0.0 /usr/local/mysql/lib ln -s /usr/local/mysql/lib/libmysqlclient.so.15.0.0 /usr/local/mysql/lib/libmysqlclient.so ln -s /usr/local/mysql/lib/libmysqlclient.so.15.0.0 /usr/local/mysql/lib/libmysqlclient.so.15
That is it! Now compile PHP again and you should see MySQLi (mysqli) in phpinfo() output. Remember to restart Apache as well (stop AND start, not graceful restart).
Recent Comments