Install the Latest version PHP on CentOS

From Brian Nelson Ramblings
Jump to: navigation, search

Install the Latest version PHP on CentOS

I currently run a development server that I need to use different versions of php, including the most recent version of php. You will notice that yum ususally does not have the lastest version of php. So you will probably need to compile the most recent version your self.

Below are the steps used to compile the lastest version PHP.

1) Install Tools to compile

You can use yum to install the tools and other files

yum install gcc-c++ httpd httpd-devel apr-devel libxml2-devel zlib zlib-devel mysql-devel openssl-devel -y

I will assume you already have httpd and mysql installed on your server, if not you might want to install them now as well.

2) Download the latest version PHP

Any time I need to download remote files I put them in /downloads, so lets create this directory if its not already created

mkdir /downloads && cd /downloads

At the time of this how to, the latest version is php5.5.11 so lets download it from


This file will save as mirror, so lets change the name to php-5.5.11.tar.gz

mv mirror php-5.5.11.tar.gz

Extract the tarball

tar -zxfv php-5.5.11.tar.gz

Move into that directory

cd php-5.5.11

Configure and Make

To get a list of configure options you can run

./configure --help

Here are the options I am currently using, you can and will propbably want to adjust this string depending on your needs.

./configure --with-config-file-path=/etc/php55 --with-config-file-scan-dir=/etc/php55.d --with-apxs2 --with-libdir=lib64/php55 --with-zlib --with-mysql --with-mysqli  --enable-ftp --with-openssl --enable-xml --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --target=x86_64-redhat-linux-gnu

You will notice that I adjust some of the folders to read php55, this is because I have other versions of php installed on this server and I like having the ability to switch between different version of php for development reasons.

Now its time to make and install php

make && make install

Now lets change some files

By default this will become the default installation, but as I have stated, this is just one version of php on the server.

Lets locate and change the php file

which php

So lets move this php55 and leave it as the current default as well

cp /usr/local/bin/php /usr/local/bin/php55

Now lets confirm its working

php55 -v
PHP 5.5.11 (cli) (built: Apr 28 2014 00:09:03) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

Now lets change the .so file that apache calls

mv /usr/lib64/httpd/modules/ /usr/lib64/httpd/modules/

Now adjust apache to use the new location

vim /etc/httpd/conf/httpd.conf

Find the file that now says

LoadModule php5_module        /usr/lib64/httpd/modules/

and change it to point to the new file

LoadModule php5_module        /usr/lib64/httpd/modules/

Now lets make the php55 config location and additional modules directory.

mkdir -p /etc/php55/ && mkdir -p /etc/php55.d/

Now lets install the php.ini file,

cp /download/php-5.5.11/php.ini-production /etc/php55/php.ini

Restart Apache/httpd

Lets restart apache/httpd to confirm everything is working correctly

httpd -t

If nothing is wrong, restart time

httpd -k restart

Testing apache with phpinfo file

Lets create a phpinfo file

echo "<?php phpinfo();" > /var/www/html/phpinfo.php

Check out that file in your browser to verify its using the correct version of php.