Topics include: programming, Apple, Unix, gadgets, large-scale web sites and other nerdy stuff.

How to get PHP 5 working with MySQL 5 on CentOS 4.x

2007-01-18 10:30:20

You'd think this would be pretty much automatic, but it hasn't been my experience.

There are two problems: CentOS 4.x distribution still has MySQL 4.1.x as the default MySQL installation. I really like to use MySQL 5 now, it's pretty stable. The other problem is that the PHP packages that claim to have MySQL enabled, actually don't. Or that's the way it seems to me, after several hours pounding my head against "yum."

Step 1: install MySQL 5

This is pretty easy:

% yum --enablerepo=centosplus install mysql-server mysql-devel
% /usr/bin/mysql_install_db
% /etc/init.d/mysqld start
% mysqladmin password your_secret_password
% mysql -h localhost -p
Enter password:

Step 2: Compile PHP

Assuming you have the standard apache httpd package installed on the machine, we have to build PHP 5 with mysql enabled. This is the only way I have been able to get PHP 5 to work. It's annoying, because you'd think that PHP + Apache + MySQL 5 would be the second most popular config on these machines.

First get PHP from

You'll also need to make sure that httpd-devel is installed so you can have apxs.

% yum install httpd-devel
% yum install libxml2 libxml2-devel flex           (you might already have these)
% tar vxzf php-5.2.0.tar.gz
% cd php-5.2.0
% ./configure --with-apxs2=/usr/sbin/apxs --with-mysql
% make
% make install

That's it. This should also take care of updating your httpd.conf to load the PHP module. Now restart apache.