The WordPress 2.7, MySQLi, PHP 5 Challenge

I finally started updating my web site! In the process I had quite the adventure last night. In case it may help someone else, here's what happened.

Firstly, I was using PHP 5 for some of my site internals, and after gazing at my handiwork on my local web server I uploaded it to my web site and gazed upon a PHP syntax error message. I don't know why PHP 4 is the default everywhere, it should be only provided as a legacy option for people with legacy apps. Fortunately I knew the server had PHP 5 because it's listed in the MOTD every time I log on. So it was a matter of finding out how to switch.

Apparently it's more secure to run PHP in CGI mode, so that the program is run with your user permissions and not apache's. The way my host handles that is to have a script in the cgi-bin directory called "php". The contents of that script are as follows:

#!/bin/sh
PHPRC="/usr/local/lib"
export PHPRC
PHP_FCGI_CHILDREN=3
export PHP_FCGI_CHILDREN
#exec "/usr/local/bin/php-fcgi"
exec "/usr/local/bin/php5.2.4"

If you try to just make a link with ln -s then you get a Forbidden error in apache. Also useful is the command killall php-fcgi which you may need to do to force Apache to start using PHP 5 after making the change in the script.

That took a while, but then I was rewarded with the beautiful sight of my html tinkering live on the internet. But eventually I discovered that my WordPress blog no longer worked. It gave this error message: "Your PHP installation appears to be missing the MySQL extension which is required by WordPress." After consulting with the server people and looking at the phpinfo() output, I discovered that not only is my host modern and forward-thinking enough to provide a PHP 5 option, but they also have replaced the PHP MySQL extension with the MySQL "Improved" extension mysqli.

Skip over 3 hours of headache and here's the conclusion. You have to install a file called db.php in the wp-content/ directory (not in the pluggins directory) that knows how to handle mysqli. I found one online but it didn't work in my configuration since it failed to set the collate property. The original file is from Justin Vincent. I also modified this one to work with the new WordPress 2.7 release, which added a few methods to the wpdb class. Here's my modified WordPress 2.7 db.php file.

I provide this driver with no warranty, expressed or implied, including, but not limited to, suitability for a purpose ... :-)