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,> 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
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:
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> 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:
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:
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 ]
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:
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>wget to make the process a bit quicker:
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.
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>
PHP Warning: date(): It is not safe to>
PHP Warning: date(): It is not safe to>
PHP Warning: date(): It is not safe to>
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.