How to Upgrade to the Latest PHP Version in CentOS Using Yum

centoscentos6linuxPHPyum

I found some blog posts about this, but it's rather lack of descriptions on possible side effects.

I could really use some detailed on these steps:

  1. How to add a repo that provides PHP 5.4 into yum
  2. Can this seamlessly replaces the current PHP version in CentOS?
  3. How can I switch back to the official repo when it supports PHP 5.4? (current 5.3.3 in my system)
  4. Will there be any potential to break PHP modules I currently using?

Note

People successfully upgraded with the same method on newer versions, and suggest removing specific versions in the question. While it is good to pin down versions in case newer versions actually breaks something, I'd like keep the latest succeed version suggested by the community as a note.

Feel free to update this if you have successfully upgraded on other versions.

  • PHP versions: 5.4, 5.5, 5.6
  • CentOS version: 5, 6

Best Answer

I followed the instructions from Install Apache/PHP 5.4.10 on Fedora 17/16, CentOS/RHEL 6.3/5.8 with a slight modification. It took maybe 10min. My exact commands are shown below. Note that the first command had to be changed from what is shown in the article. The change was from epel-release-6-7.noarch.rpm to epel-release-6-8.noarch.rpm.

  1. How to add a repo that provides PHP 5.4 into yum?

    yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
    yum install http://rpms.remirepo.net/enterprise/remi-release-6.rpm
    
  2. Can this seamlessly replace the current PHP version in CentOS? For me the following commands worked and none of my existing PHP web pages broke. Your mileage may vary.

    yum --enablerepo=remi install httpd php php-common
    yum --enablerepo=remi install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml
    service httpd restart
    
  3. How can I switch back to the official repo when it supports PHP5.4? I have not tested the commands to remove and re-install PHP from CentOS repositories, but these should work.

    # Remove the Remi packages. Note the reversed command order
    yum remove php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml
    yum  remove httpd php php-common
    # Install the CentOS packages. 
    yum install httpd php php-common
    yum install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml
    
  4. Will there be any potential to break PHP modules I [sic] currently using? Yes. Using a recent version of CentOS (6.2?) with Zend installed using the Zend installer, the above upgrade broke Zend.

All the above commands were run as root. Best practice is to login as a non-privileged user and use sudo. (This is a development VM with a current snapshot...)

Also, do NOT enable the Remi repository by default - in the past I got clever and enabled it by default and things broke, even with repository priority.

Related Topic