I’m finding that more and more software developers are being quite inconsiderate and are making code that requires PHP 5.3. Since many server-based and long-term support distros are still on PHP 5.2, this can make things difficult quickly.
I’ll share how I upgraded one of my servers, but I do need to let you know about some specifics about my setup as your setup may be different and require different steps to upgrade.
When I started, my system ran CentOS 5.5 and PHP 5.2.16. Now it is running CentOS 5.6 and PHP 5.3.3.
You won’t be able to follow these steps without root access, so that is definitely a requirement. I’m also running Apache. You may be using a different web server, but if you don’t know what I’m talking about, you are running Apache. I assume that if you run a different server, you will know what to change in my steps.
Upgrade CentOS 5.5 to CentOS 5.6
I found that CentOS 5.6, released earlier this year, had package support for PHP 5.3. That made me very excited. I thought that all I needed to do was to upgrade my distro, and I would be done (I would later find that I was naïve).
Fortunately, upgrading CentOS is very easy. I simply ran the following command to spawn a huge amount of work for the server:
[user@server ~]$ sudo yum update [sudo] password for user: Loaded plugins: fastestmirror, priorities Loading mirror speeds from cached hostfile * addons: mirrors.tummy.com * base: centos.mirror.lstn.net * epel: fedora-epel.mirror.lstn.net * extras: mirror.ubiquityservers.com * updates: mirror.steadfast.net Setting up Update Process Resolving Dependencies --> Running transaction check ---> Package amtu.x86_64 0:1.0.6-2.el5 set to be updated ---> Package asciidoc.noarch 0:8.6.5-1.el5.rf set to be updated ---> Package audit.x86_64 0:1.7.18-2.el5 set to be updated ... Install 5 Package(s) Upgrade 208 Package(s) Remove 2 Package(s) Reinstall 0 Package(s) Downgrade 0 Package(s) Total download size: 309 M Is this ok [y/N]: y Downloading Packages: (1/213): avahi-glib-0.6.16-10.el5_6.x86_64.rpm | 15 kB 00:00 (2/213): avahi-glib-0.6.16-10.el5_6.i386.rpm | 15 kB 00:00 (3/213): rng-utils-2.0-4.el5.x86_64.rpm | 17 kB 00:00 ... Complete! [user@server ~]$
Notice the white “y” toward the bottom. Before it does anything, you must answer its question with a “y”. Just hitting enter will cancel the upgrade.
This will take between 5-30 minutes on average depending on the number of packages to be upgraded, the speed of your system, and your servers connection speed. So pop open a root beer and wait for everything to finish up.
Reboot the server
Since this should have installed a new kernel for your system, you will want to reboot so that this new kernel can be loaded.
Rebooting a server can be a scary thing. Make sure that you know how to contact your hosting company’s tech support in case there are any problems with connecting to the server after the reboot. Also make sure that you notify any people that may be upset about the reboot before you do it.
Upgrade PHP 5.2 to PHP 5.3
I booted up my system and found that my PHP version was not upgraded:
[user@server ~]$ php -v PHP 5.2.11 (cli) (built: Jan 17 2011 01:47:19) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
This version of CentOS took the odd step of having both PHP 5.2 and PHP 5.3 packages. The main packages are 5.2 while another set with modified names are 5.3. For instance, the PHP 5.2 main package is php
while the PHP 5.3 one is php53
.
I still have no idea why they decided to do things this way, but I guess it has to do with some software not supporting 5.3 properly yet.
Since I couldn’t just install the php53
packages as they would conflict with the php
packages, I had to remove all the existing PHP packages and install the new ones. This meant that I had to take stock of exactly what packages I had to remove and replace.
I used the yum
commands list
command to quickly get this information:
[user@server ~]$ yum list installed | grep php | cut -d' ' -f1 php.x86_64 php-cli.x86_64 php-common.x86_64 php-devel.x86_64 php-gd.x86_64 php-mbstring.x86_64 php-mysql.x86_64 php-mcrypt.x86_64 php-pdo.x86_64 php-pear.noarch php-pgsql.x86_64 php-xml.x86_64 php-xmlrpc.x86_64 [user@server ~]$
The | cut -d' ' -f1
part at the end is just some fanciness to show only the package name and not the extra cruft.
Next I checked to make sure that those packages were available for php53
:
[user@server ~]$ yum search php53 | cut -d' ' -f1 | grep php php53.x86_64 php53-bcmath.x86_64 php53-cli.x86_64 php53-common.x86_64 php53-dba.x86_64 php53-devel.x86_64 php53-gd.x86_64 php53-imap.x86_64 php53-intl.x86_64 php53-ldap.x86_64 php53-mbstring.x86_64 php53-mysql.x86_64 php53-odbc.x86_64 php53-pdo.x86_64 php53-pgsql.x86_64 php53-process.x86_64 php53-pspell.x86_64 php53-snmp.x86_64 php53-soap.x86_64 php53-xml.x86_64 php53-xmlrpc.x86_64 [use@server ~]$
I quickly noticed that neither php53-mcrypt.x86_64
nor php53-pear.noarch
were available. I would have to install these manually.
First, I shut down the Apache server as I didn’t want people going to broken pages as I did these updates:
[user@server ~]$ sudo service httpd stop Stopping httpd: [ OK ] [user@server ~]$
Next, I remove the old PHP packages:
[user@server ~]$ sudo yum remove php php-cli php-common php-devel php-gd php-mbstring php-mysql php-mcrypt php-pdo php-pear php-pgsql php-xml php-xmlrpc Loaded plugins: fastestmirror, priorities Setting up Remove Process Resolving Dependencies --> Running transaction check ---> Package php.x86_64 0:5.2.16-jason.1 set to be erased ... Remove 13 Package(s) Reinstall 0 Package(s) Downgrade 0 Package(s) Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test ... Complete! [user@server ~]$
Finally, I installed the available replacement packages:
[user@server ~]$ sudo yum install php53 php53-cli php53-common php53-devel php53-gd php53-mbstring php53-mysql php53-pdo php53-pgsql php53-xml php53-xmlrpc Loaded plugins: fastestmirror, priorities Loading mirror speeds from cached hostfile * base: centos.mirror.lstn.net * epel: fedora-epel.mirror.lstn.net * extras: mirror.ubiquityservers.com * updates: mirror.steadfast.net Setting up Install Process ... Install 2 Package(s) Upgrade 0 Package(s) Total download size: 18.5 M Is this ok [y/N]: y Downloading Packages: ... Complete! [user@server ~]$
Now it’s time to get the other PHP elements that were not available as packages.
Install PHP mcrypt
The php53-mcrypt
package wasn’t available, so we have to install it manually. The following steps will accomplish this.
We first need to install the development package for mcrypt:
[user@server ~]$ sudo yum install php53-devel libmcrypt-devel gcc ...
PHP’s mcrypt extension can be compiled and installed from the source code, so we need to download and unpackage the PHP 5.3.3 source. You can find a download link on the PHP releases page. I used wget
to make the process a bit quicker:
[user@server ~]$ wget http://museum.php.net/php5/php-5.3.3.tar.gz --2011-12-07 14:32:00-- http://museum.php.net/php5/php-5.3.3.tar.gz Resolving museum.php.net... 67.23.255.166 Connecting to museum.php.net|67.23.255.166|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 13921529 (13M) [application/x-gzip] Saving to: 'php-5.3.3.tar.gz' 100%[=================================================>] 13,921,529 2.04M/s in 6.6s 2011-06-24 19:10:40 (2.00 MB/s) - `php-5.3.3.tar.gz' saved [13921529/13921529] [user@server ~]$ tar xf php-5.3.3.tar.gz [user@server ~]$
Now we need to compile and install the mcrypt extension:
[user@server ~]$ cd php-5.3.3/ext/mcrypt/ [user@server mcrypt]$ phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626 [user@server mcrypt]$ aclocal [user@server mcrypt]$ ./configure checking for egrep... grep -E checking for a sed that does not truncate output... /bin/sed checking for cc... cc ... checking how to hardcode library paths into programs... immediate configure: creating ./config.status config.status: creating config.h [user@server mcrypt]$ make .... Build complete. Don't forget to run 'make test'. [user@server mcrypt]$ make test Build complete. Don't forget to run 'make test'. ===================================================================== PHP : /usr/bin/php PHP_SAPI : cli PHP_VERSION : 5.3.3 ZEND_VERSION: 2.3.0 ... Do you want to send this report now? [Yns]: y Please enter your email address. (Your address will be mangled so that it will not go out on any mailinglist in plain text): user@example.com Posting to qa.php.net /buildtest-process.php Thank you for helping to make PHP better. [user@server mcrypt]$ sudo make install Installing shared extensions: /usr/lib64/php/modules/ [user@server mcrypt]$
Now all we have to do is set up the mcrypt.ini
file so that the mcrypt extension loads with PHP. This file needs to reside at /etc/php.d/mcrypt.ini
.
[user@server mcrypt]$ echo -e "; Enable mcrypt extension module\nextension=mcrypt.so" | sudo tee /etc/php.d/mcrypt.ini ; Enable mcrypt extension module extension=mcrypt.so [user@server mcrypt]$
Restarting the Apache server will load our new changes. (Thanks to Michael DePetrillo for pointing out that I originally skipped documenting this step.)
[user@server mcrypt]$ sudo service apache2 restart * Restarting web server apache2 ... waiting [ OK ] [user@server mcrypt]$
Install PHP Pear
Finally, I need to install PHP Pear. If you haven’t used it, it is essentially a code repository tool for easily installing, upgrading, and managing hosted code. It is basically PHP’s version of Perl’s CPAN.
Installing this is fairly straightforward.
[user@server ~]$ wget http://pear.php.net/go-pear.phar --2011-06-24 15:18:22-- http://pear.php.net/go-pear.phar Resolving pear.php.net... 78.129.214.25 Connecting to pear.php.net|78.129.214.25|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 3680148 (3.5M) [application/octet-stream] Saving to: `go-pear.phar' 100%[=================================================>] 3,680,148 523K/s in 7.3s 2011-06-24 15:18:29 (491 KB/s) - `go-pear.phar' saved [3680148/3680148] FINISHED --2011-06-24 15:18:29-- Downloaded: 1 files, 3.5M in 7.3s (491 KB/s) [user@server ~]$ sudo php go-pear.phar Below is a suggested file layout for your new PEAR installation. To change individual locations, type the number in front of the directory. Type 'all' to change all of them or simply press Enter to accept these locations. ... Beginning install... PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead in phar:///usr/src/go-pear.phar/PEAR/Registry.php on line 1012 PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead in phar:///usr/src/go-pear.phar/PEAR/Registry.php on line 1012 PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead in phar:///usr/src/go-pear.phar/PEAR/Registry.php on line 1012 PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead in phar:///usr/src/go-pear.phar/PEAR/Registry.php on line 1012 Configuration written to /etc/pear.conf... Initialized registry... ... PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer) PEAR: To install optional features use "pear install pear/PEAR#featurename" The 'pear' command is now at your service at /usr/bin/pear [user@server ~]$
Notice that ugly mess about the date()
function. It’s PHP 5.3-specific. I posted how to fix it here.
Final Thoughts
All in all, this was much more complex than I had anticipated. I can understand why the CentOS devs had decided to make a separate set of packages for PHP 5.3, but it really has made things difficult. I do have to warn you that many other packages will start to take issue with this setup as they will have dependency requirements for the php
package which naturally conflicts with the php53
. This leads me to think that they have done this in a way that the repo was not supposed to support as the dependencies should not break in this fashion.
Oh well. Nothing is perfect.
Did I help you?
Thanks Chris, very helpful and well written.
I used it to install CakePHP on my hotspot system, as described here (http://sourceforge.net/apps/trac/hotcakes/wiki/yfi_setup_centos_cake).
But now I have a problem: if I run
# yum groupinstall ‘Web Server’
it fails, telling me that php-cli is not compatible with php53-cli.
In other words, it seems I can either downgrade to 5.1 (but then CakePHP does not work), or keep 5.3 (which prevents me from running Apache).
You have a suggestion for me?
Thanks,
Mauro
The
groupinstall
command ofyum
simply installs a number of packages. Included in the “Web Server” group is the “php” package. Since this will naturally conflict with the “php53” packages, you can’t use the group install method. Instead, simply install the desired packages manually.You can get a list of all the packages that are part of the “Web Server” group by running the following:
Problem solved. Thanks so much for clear and quick answer.
Mauro
Hi Chris again
I’ve opened a request on daloradius forum to better investigate
https://sourceforge.net/projects/daloradius/forums/forum/684102/topic/5580636/index/page/1
however I’m wondering if your process to manually install pear is equivalent to the features provided by the php-pear and php-pear-DB that I had previously installed. In fact, Daloradius is not able to open mySql tables after I replace php-pear and php-pear-DB (both php 5.1) with PEAR installed through wget http://pear.php.net/go-pear.phar.
Thanks,
Mauro
I’m really not sure what I could do to help. I have no familiarity with daloRADIUS and the forum there seems to be responsive.
Since you are getting 500 errors, you should be able to find a PHP error log that contains the relevant errors. Posting those errors in the forum help request should help them quickly identify any potential issue and get it resolved.
Hi Chris,
Thanks for the excellent information.
I have just one question, there is some risk if I upgrade the PHP having a running mysql? or is necessary to stop the mysql?
Thanks a lot.
Liza
I’m not aware of any issues caused by having MySQL running while upgrading. I’ve never stopped MySQL when I’ve upgraded anything (not even MySQL itself), and I’ve never experienced any odd behavior or issues.
oh At least ,, my Kloxo now have a PHP5.3 😀 thanx for the tutorials ,,
beacuse iam confuse before 🙂 ,,
regards :
awan
Thank you, useful info!
Fantastic! Super tutorial, thank you I am now running PHP 5.3.3 without a hitch, with all the packages I needed and had installed! Just a quick question: when I first ran the ‘yum list installed’ for php, php-pear was in the list of installed packages, so I proceeded to re-install it as outlined after the PHP upgrade. Now it is installed and working, but it does not show up in the list for ‘yum list installed’ anymore, all I show is:
php53.i386
php53-cli.i386
php53-common.i386
php53-gd.i386
php53-ldap.i386
php53-mbstring.i386
php53-mysql.i386
php53-pdo.i386
php53-xml.i386
It’s working, it’s there, but not in the list anymore. Should it be there, or is it different for PHP 5.3.3?
It isn’t listed because a PHP 5.3-compatible PEAR is not present in the repos. Due to this, the instructions install PEAR using the install script downloaded from the PEAR site.
OK duh that makes perfect sense :0)
Still getting used to how yum and repos work, but PHP 5.3.3 is installed successfully on my machine. Wouldn’t have been able to do it without your excellent tutorial, thanks again!
Hi Man,
Really great step by step info. So informative ! it had save me a lot of time.
Thanks,
Erwin
[…] Upgrade PHP 5.1/5.2 to 5.3 on CentOS Code: […]
The easiest method to update PHP from older version 5.1.x to 5.3.x & the method is called “NASHOT’s Method”.
================== START ====================================
NASHOT’s Method:
Step 1) Go to GUI mode(X-Windows preferably Gnome desktop) & then “Add/Remove Software section(Package Manager).
Step 2) Click on Search TAB & enter the search string as php & set the radio button to “Installed Packages” & Hit the Search Button.
Step 3) Search result will show existing php modules with Ticked check-boxes at the beginning. It’s something like this:
[/] php-5.1.x…..
[/] php-common-5.1.x……
[/] php-cli-5.1.x……
[/] php-ldap-5.1.x……
Etc…Etc…
Step 4) Now Un-Tick the Check-Boxes from all resulted lines & then Click on Apply Button. This will remove existing PHP version Modules.
Step 5) Inside the “Package Manager” click on Search Tab & enter the search string as php53 & set the radio button to “All Packages” & Hit Search Button.
Step 6) Search shows many Result lines related to new PHP version 5.3.x with Un-Ticked Check-Box before each line.
Step 7) Now Tick the Check-Boxes from all resulted lines & then Click on Apply Button.
Now “Package Manager” will begins to check for Dependancy Modules for Selected PHP Modules & Downloads the new PHP 5.3.x package modules & then installs Automatically.
Now Restart your system & check the version of the installed PHP Version by using “php -v” command & result should be PHP 5.3.x
Please NOTE: If your installation halts at “Checking Dependancy”, then check for selection of “PHP53-odbc64-5.3.x…..”. Actually there are 2 odbc packages & each meant for 32bit & 64bit version of OS. So select only ONE odbc package which is compatible with your OS.
=================== END ===================================
That may work well for some, but I feel that many that use these instructions are using them because they are updating a server which doesn’t have X, just as I had to do before writting this post.
It’s works!
Fantastic! Thanks.
Cheers Chris! Very helpful!
[root@localhost mcrypt]# aclocal
configure.in:8: warning: LT_AC_PROG_SED is m4_require’d but is not m4_defun’d
configure.in:8: LT_AC_PROG_SED is required by…
acinclude.m4:2683: PHP_CONFIG_NICE is expanded from…
configure.in:8: the top level
Error while installting mcrypt..
Thank you
Found Solution
Need to Create symlinks
cd /usr/share/aclocal
ln -s /usr/lib/php/build/ltmain.sh ltmain.sh
ln -s /usr/lib/php/build/libtool.m4 libtool.m4
run from phpsize
Cool stuff. I used it and it works. Thanks bro!
Hi Chris,
Thank you for this excellent info
IT WORKS!!
Thanks for the detailed article but you forgot to restart apache at the end.
Fixed. Thanks.
[…] 5.8. To prevent the future problem I decide to upgrade php version to 5.3 now. I followed the instruction of Chris Jean to do the upgrade. But still some issue I fixed by myself. So I put the screen shoot below for […]
Very helpful. thank you
I got following error/msg, but solved with “sudo yum install gcc”
checking whether to compile debug version… no
checking for gcc… no
checking for cc… no
checking for cl.exe… no
configure: error: in `/home/gnotes/sphinx’:
configure: error: no acceptable C compiler found in $PATH
See `config.log’ for more details.
Thanks. I updated the post to install
gcc
whenphp53-devel
andlibmcrypt-devel
are installed.Thanks so mush for this update info,
Thank you very much. This is the perfect guide to compile module from source file. I was looking from a long time but didn’t get any solution but after this block issue has been resolved .
Wow Thanks man o/