[转]How to install PHP 5.3 on CentOS

在DIAHosting买了一个VPS,自带PHP5.1.6.我想安装wordpress,但是由于版本比较新,要求PHP也要是5.2以上的,于是我就安装了PHP5.3.20

----------------------------------------------------------------------------------------------------------------------------

By David Gewirtz

Let's talk about PHP for a moment. In particular, let's talk about PHP's release history. PHP 5.1 was released in 2005. PHP 5.2 was released almost exactly a year later, in 2006. PHP 5.3, on the other hand, took four more years -- until 2009 -- to be released.

Now, there's a reason 5.3 took so long. There was a profound change to the language: namespaces. PHP is pretty much of an ad-hoc language, and without namespaces, object names had a tendency to run over each other. Namespaces changes that, so 5.3 was a big load of work. Now, personally, I'm not thrilled with exactly how PHP implemented namespaces, but that's a geekout for another article.

Anyway, the point is this: PHP 5.3 has been out for two years and has gone through five subsequent updated, bringing the current release to PHP 5.3.5.

Why am I telling you all this?

I'm telling you all this because CentOS, the community enterprise version Redhat's Fedora core, only supports PHP 5.1, a version of the language that's now more than five years -- more than 1,900 days -- old.

I like CentOS and one of our favorite ISPs uses CentOS 5.5. But when you install CentOS 5.5 (the latest release), you get what's essentially an archaic version of PHP. Yes, I know that sometimes the bugs haven't been pounded out, and when PHP 5.3 was released, there were bugs. But now that PHP 5.3 itself is two years old, it's a pretty solid beast.

So, net-net-net, if you want to run CentOS 5.5 and PHP 5.3, you have to modify your system.

Updating to PHP 5.3

This takes a number of steps. You need to remove the old PHP and install the new one. Because I wanted a PHP that's tuned for CentOS, I wanted to use existing PHP packages. But here's the rub: the official CentOS package repository doesn't support PHP 5.3 (or PHP 5.2, for that matter).

The first thing you'll need to do is add new repositories to your system. The following three commands will do the trick.

 # rpm -Uhv http:\//apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
 # rpm -Uvh http:\//download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
 # rpm -Uvh http:\//dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1.0-6.ius.el5.noarch.rpm

It should be noted that these versions move around all the time and you may have to do some poking around on the sites. I originally found references to these builds as epel-release-5-3, which didn't work, but I found epel-release-5-4, and since that worked, I went ahead and used that.

Once you've added repositories, you can use the yum package manager to install PHP. First, assuming you have a basic CentOS install, you'll need to remove PHP and it's associated friends. Here's how:

 # yum erase php php-pear php-mysql php-cli php-common

Then, you can go ahead and install PHP 5.3. I used the following commands. I broke them up simply because it was easier to present in the article, but you could string all the packages together on one command line.

 # yum install php53u php53u-pear php53u-cli php53u-common php53u-gd
 # yum install php53u-mbstring php53u-mcrypt php53u-mysql php53u-soap
 # yum install php53u-xml php53u-xmlrpc php53u-bcmath

If you'd prefer to install 5.2, you can do so with this set of commands:

 # yum install php52 php52-pear php52-cli php52-common php52-gd
 # yum install php52-mbstring php52-mcrypt php52-mysql php52-soap
 # yum install php52-xml php52-xmlrpc php52-bcmath

There you go. Simply type "php -v" to your command line to verify the install.

Word of warning

One final word of warning: screwing with your package manager could break your Linux install. I followed one guide and the result was that yum wanted to uninstall just about everything. I caught it in time and stopped, but baaaaad things could happen.

Bad things could even happen if you follow my directions. So if you do this, make sure you think through your steps and know what you're doing. If you break your Linux distro, I can't help you fix it. So, you know, you were warned!

原文地址:https://www.cnblogs.com/coolicer/p/2860320.html