Update 20th June 2009 – I found a bug in PHP 5.2.6, so I have compiled 5.2.10 rpms and provided a repository from which to install them, check out the article here.
Update 19th May 2009 – I have written an article here detailing how to build RPMs and install some additional php extensions, which although part of the PHP source distribution, is not included in this installation (extensions mcrypt, mhash, tidy, mssql)
Update 13th June 2009 – I’ve made the guide easier by using yum options to install the testing RPMs rather than using yum-priorities.
Redhat-based distributions tend to supply out of date releases of software. This isn’t technically a bad thing. They extensively test their updates before releasing out to the public, and upstream security fixes from the latest versions, meaning that they can be extremely stable when compared to some other distributions such as Debian-based Ubuntu.
However, this means that you rarely get new features added, until there is a new major release. Again this isn’t all bad, as new features add new bugs, which affect stability.
PHP 5.1.6, which is part of the base CentOS repository, was released 24-Aug-2006, almost 3 years ago. Since then, PHP 5.2 has been released, gone through 9 release builds since, and is considered stable for production environments.
Installation
There is a version of PHP (5.2.6) in CentOS’s Testing repository. You could either download each rpm and install, or set up your yum to install from the testing repository.
Install the testing repository’s GPG key:
rpm --import http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
And download the CentOS-Testing repo file:
cd /etc/yum.repos.d wget http://dev.centos.org/centos/5/CentOS-Testing.repo
Now you can install/update to PHP 5.2.6 by running
yum --disablerepo=* --enablerepo=c5-testing update php
Reasoning
As much as I have wanted to be using PHP 5.2, using just CentOS’s normal repositories meant not being able to use its new features.
It appears now that Zend Framework no longer supports PHP 5.1 in all of its sub-components, take for example Zend_View_Helper_Placeholder_Container_Abstract since ZF 1.7.5, and its derivative classes. This extends from ArrayObject, and it uses the php method ArrayObject::ksort(). This is not available in the version of SPL contained in Centos 5’s PHP 5.1.6. It causes a fatal error when used.
So, the question is should I write a patch for Zend Framework, which wont get incorporated into their code, or upgrade to PHP 5.2?
I chose the former initially, which fixes that problem, but I don’t know if there are any other bugs which might crop up in the library, so I’ve now chosen to update PHP.
rpm -import http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
this command is not working
showing import:no option
Odd, rpm’s documentation says –import, but -import did the same on the setups I’ve installed this on. I’ve updated the article to show the correct command:
rpm –import http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
Could someone help me get this installed. It keeps failing:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Update Process
Resolving Dependencies
–> Running transaction check
–> Processing Dependency: php Package php.x86_64 0:5.2.6-2.el5s2 set to be updated
–> Processing Dependency: php-common = 5.2.6-2.el5s2 for package: php
–> Processing Dependency: php-cli = 5.2.6-2.el5s2 for package: php
–> Running transaction check
–> Processing Dependency: php Processing Dependency: php-common = 5.1.6-23.2.el5_3 for package: php-pdo
–> Processing Dependency: php-common = 5.1.6-23.2.el5_3 for package: php-mbstring
–> Processing Dependency: php-common = 5.1.6-23.2.el5_3 for package: php-xml
–> Processing Dependency: php-common = 5.1.6-23.2.el5_3 for package: php-mysql
–> Processing Dependency: php-common = 5.1.6-23.2.el5_3 for package: php-gd
–> Processing Dependency: php-common = 5.1.6-23.2.el5_3 for package: php-pgsql
–> Processing Dependency: php-common = 5.1.6-23.2.el5_3 for package: php-imap
—> Package php-cli.x86_64 0:5.2.6-2.el5s2 set to be updated
—> Package php-common.x86_64 0:5.2.6-2.el5s2 set to be updated
–> Running transaction check
—> Package php-xml.x86_64 0:5.2.6-2.el5s2 set to be updated
—> Package php-mysql.x86_64 0:5.2.6-2.el5s2 set to be updated
—> Package php-pgsql.x86_64 0:5.2.6-2.el5s2 set to be updated
–> Processing Dependency: libpq.so.5()(64bit) for package: php-pgsql
–> Processing Dependency: php Package php-gd.x86_64 0:5.2.6-2.el5s2 set to be updated
—> Package php-pdo.x86_64 0:5.2.6-2.el5s2 set to be updated
—> Package php-mbstring.x86_64 0:5.2.6-2.el5s2 set to be updated
—> Package php-imap.x86_64 0:5.2.6-2.el5s2 set to be updated
–> Running transaction check
–> Processing Dependency: libpq.so.4()(64bit) for package: apr-util
—> Package postgresql-libs.x86_64 0:8.2.9-1.el5s2 set to be updated
–> Processing Dependency: php Running transaction check
–> Processing Dependency: php Package postgresqlclient81.x86_64 0:8.1.11-1.el5s2 set to be updated
–> Finished Dependency Resolution
php-sqlite2-5.1.6-200705230937.x86_64 from installed has depsolving problems
–> Missing Dependency: php <= 5.2.0 is needed by package php-sqlite2-5.1.6-200705230937.x86_64 (installed)
Error: Missing Dependency: php <= 5.2.0 is needed by package php-sqlite2-5.1.6-200705230937.x86_64 (installed)
sqlite2 seems to be an extension included in the source of the php distrobution, but CentOS chose not to create a rpm for it. I guess it is since PHP also includes sqlite3 as part of the PDO extension.
Did you install it from a 3rd party repo?
What you could do is compile the source version of the extension, by following the part of my other guide to get the php source (php.net no longer supplies 5.2.6), or doing the following:
yum remove -y php-sqlite
yum install php-devel # if you don’t already have it installed
useradd mockbuild
mkdir /usr/src/redhat
rpm -Uhv http://dev.centos.org/centos/5/testing/SRPMS/php-5.2.6-2.el5s2.src.rpm
Then you can extract the php source and compile the extension using phpize:
cd /usr/src/redhat/SOURCES
tar zxvf php-5.2.6.tar.gz
cd php-5.2.6/ext/sqlite
phpize
./configure
make install
then add a php.d ini to load the module:
echo
I successfully upgraded my php, running php -v returns PHP 5.2.6,
But now when i want to install php-devel i get the following output:
–> Running transaction check
—> Package php-devel.i386 0:5.1.6-23.2.el5_3 set to be updated
–> Processing Dependency: php = 5.1.6-23.2.el5_3 for package: php-devel
–> Finished Dependency Resolution
Error: Missing Dependency: php = 5.1.6-23.2.el5_3 is needed by package php-devel
Anyone can tell me how i can install php-dev?
Are you using the yum install –disablerepo=* –enablerepo=c5-testing php-devel
If that’s still a problem, try installing the rpm direct:
rpm -Uvh http://dev.centos.org/centos/5/testing/i386/php-devel-5.2.6-2.el5s2.i386.rpm
Thank you so much for this simple tutorial! I followed the instructions above and php updated perfectly!
remember it’s two “-” infront of
rpm –import
yum –disablerepo=* –enablerepo=c5-testing update php
Oh noticed that my php version is 5.2.6….Where can I get 5.2.10 or even better 5.3.0
I just compiled the i386 php 5.3.0 last night, just finished compiling the x86_64.
I’ve set up my own RPM repository and made a blog post about putting php 5.2.10 on it here http://www.webtatic.com/blog/2009/06/php-529-on-centos-5/
However I’ve now put my php 5.3.0 rpms on there now, so if you just follow the instructions on that article you can get them now. I’ll sort out a new blog post about it soon.
Ta very much. Worked a treat