Home > Guides, Web Development > Installing PHP 6 on CentOS 5

Installing PHP 6 on CentOS 5

June 15th, 2009

I started playing in PHP 5.3 with Zend’s Early Access 7.0 Studio and Server CE and wanted to put it on my web server. Problem: It isn’t released yet and the library name is “php5″, same as PHP 5.2. I didn’t want to replace my production-ready PHP installation with a release candidate. I’m sure that would make my clients happy about unknown security holes, yadda yadda. The only solution is to install PHP 6 and enable it by virtual domain or directory. Please note that it is entirely possible to install PHP 5.3 along side PHP 5.2.9 using the first as CGI, but I want to avoid the confusion.

My CentOS 5 64-bit server is a VPS from 1&1.

Final notes before we get started. I did a “yum update” to bring my system to the latest everything. And no, installing libxml2 or icu via yum won’t help you. You can skip the gmake test, it is 7180 individual tests that can take a LOT of time on slower servers. CentOS is based on RedHat, so this will likely work with it as well.


# install the stuff you need to compile

yum install gcc gcc-c++.x86_64
yum install mysql-devel.x86_64 libpng-devel.x86_64 libjpeg-devel.x86_64

# compile and install icu where php6 can find it

mkdir /usr/local/icu
wget ftp://ftp.software.ibm.com/software/globalization/icu/3.6/icu4c-3_6-src.tgz
tar xkmfz icu4c-3_6-src.tgz
cd icu/source
./configure --prefix=/usr/local/icu
gmake
gmake install
cd ../..

# compile and install icu where php6 can find it

mkdir /usr/local/libxml2
wget ftp://xmlsoft.org/libxml2/libxml2-2.7.3.tar.gz
tar xkmfz libxml2-2.7.3.tar.gz
cd libxml2-2.7.3
autoreconf
./configure --prefix=/usr/local/libxml2
gmake
gmake install
cd ..

# compile php6 from http://snaps.php.net
# with libxml2, GD (jpeg + png) and MySQL

# make the config path
mkdir /etc/php6
mkdir /etc/php6.d

# download and extract the latest path, get it from snaps.php.net
wget http://snaps.php.net/php6.0-############
tar xkmfz php6.0-############
cd ~/php6.0-############

# refresh the conf
autoconf

# paste in this entire block and press enter:
./configure \
--prefix=/usr/local/php6 \
--with-config-file-path=/etc/php6 \
--with-config-file-scan-dir=/etc/php6.d \
--with-icu-dir=/usr/local/icu \
--with-libxml-dir=/usr/local/libxml2 \
--with-gd \
--with-jpeg-dir=/usr/lib64 \
--with-png-dir=/usr/lib64 \
--with-zlib-dir=/usr/lib64 \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock=/var/lib/mysql/mysql.sock

# alt for mysqli: --with-mysqli=/usr/bin/mysql_config

# compile and install. you can skip test if you want.
gmake
gmake test
gmake install

# prepare configuration
cp php.ini-* /etc/php6

# and ONE of the following to set up your php.ini

# if you plan to host pages to the outside world
cp php.ini-production /etc/php6/php.ini

# if you plan to use this installation as a test site for development
cp php.ini-development /etc/php6 php.ini

# if you have issues with mysql:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

Oh yeah, and running along side PHP 5? Toss something like this in a new file: /etc/httpd/conf.d/php6.conf


ScriptAlias /php6-cgi /usr/local/php6/bin/php-cgi
Action application/x-http-php6 /php6-cgi
AddHandler application/x-http-php6 .php6

Now anything .php6 will run php6 as cgi. If you have problems with CGI or MySQL, try nixing SuExec first. If you want to use it, you’ll need to be recompile it with a special folder permission for PHP 6.

Josh Guides, Web Development , , , ,

Comments are closed.