Upgrading PHP on CentOS 6.5 (Final)

203,177

Solution 1

As Jacob mentioned, the CentOS packages repo appears to only have PHP 5.3 available at the moment. But these commands seemed to work for me...

rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
yum remove php-common       # Need to remove this, otherwise it conflicts
yum install php56w
yum install php56w-mysql
yum install php56w-common
yum install php56w-pdo
yum install php56w-opcache
php --version               # Verify version has been upgraded

You can alternatively use php54w or php55w if required.

CAUTION!
This may potentially break your website if it doesn't fully resolve all your dependencies, so you may need a couple of extra packages in some cases. See here for a list of other PHP 5.6 modules that are available.

If you encounter a problem and need to reset back to the default, you can use these commands:

sudo yum remove php56w
sudo yum remove php56w-common
sudo yum install php-common
sudo yum install php-mysql
sudo yum install php

(Thanks Fabrizio Bartolomucci)

Solution 2

For CentOS 6, PHP 5.3.3 is the latest version of PHP available through the official CentOS package repository. Keep in mind, even though PHP 5.3.3 was released July 22, 2010, the official CentOS 6 PHP package was updated November 24, 2013. Why? Critical bug fixes are backported. See this question for more information: "Why are outdated packages installed by yum on CentOS? (specifically PHP 5.1) How to fix?"

If you'd like to use a more recent version of PHP, Les RPM de Remi offers CentOS PHP packages via a repository that you can add to the yum package manager. To add it as a yum repository, follow the site's instructions.

Note: Questions of this variety are probably better suited for Server Fault.

Solution 3

This is the easiest way that worked for me: To install PHP 5.6 on CentOS 6 or 7:

CentOS 6. Enter the following commands in the order shown:

yum -y update
yum -y install epel-release
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
wget https://centos6.iuscommunity.org/ius-release.rpm
rpm -Uvh ius-release*.rpm
yum -y update
yum -y install php56u php56u-opcache php56u-xml php56u-mcrypt php56u-gd php56u-devel php56u-mysql php56u-intl php56u-mbstring php56u-bcmath

CentOS 7. Enter the following commands in the order shown:

yum -y update
yum -y install epel-release
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget https://centos7.iuscommunity.org/ius-release.rpm
rpm -Uvh ius-release*.rpm
yum -y update
yum -y install php56u php56u-opcache php56u-xml php56u-mcrypt php56u-gd php56u-devel php56u-mysql php56u-intl php56u-mbstring php56u-bcmath

Sorry - I'm unable to post the source URL - due to reputation

Solution 4

  1. Verify current version of PHP Type in the following to see the current PHP version:

    php -v

    Should output something like:

    PHP 5.3.3 (cli) (built: Jul 9 2015 17:39:00) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

  2. Install the Remi and EPEL RPM repositories

If you haven’t already done so, install the Remi and EPEL repositories

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm && rpm -Uvh epel-release-latest-6.noarch.rpm



wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm && rpm -Uvh remi-release-6*.rpm

Enable the REMI repository globally:

nano /etc/yum.repos.d/remi.repo

Under the section that looks like [remi] make the following changes:

[remi]
name=Remi's RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

Also, under the section that looks like [remi-php55] make the following changes:

[remi-php56]
name=Remi's PHP 5.6 RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/php56/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/php56/mirror
# WARNING: If you enable this repository, you must also enable "remi"
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

Type CTRL-O to save and CTRL-X to close the editor

  1. Upgrade PHP 5.3 to PHP 5.6 Now we can upgrade PHP. Simply type in the following command:

    yum -y upgrade php*

Once the update has completed, let’s verify that you have PHP 5.6 installed:

php -v

Should see output similar to the following:

PHP 5.6.14 (cli) (built: Sep 30 2015 14:07:43) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

Solution 5

Steps for upgrading to PHP7 on CentOS 6 system. Taken from install-php-7-in-centos-6

To install latest PHP 7, you need to add EPEL and Remi repository to your CentOS 6 system

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

Now install yum-utils, a group of useful tools that enhance yum’s default package management features

yum install yum-utils

In this step, you need to enable Remi repository using yum-config-manager utility, as the default repository for installing PHP.

yum-config-manager --enable remi-php70

If you want to install PHP 7.1 or PHP 7.2 on CentOS 6, just enable it as shown.

yum-config-manager --enable remi-php71 
yum-config-manager --enable remi-php72

Then finally install PHP 7 on CentOS 6 with all necessary PHP modules using the following command.

yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo

Double check the installed version of PHP on your system as follows.

php -V 
Share:
203,177
BCLtd
Author by

BCLtd

I Developing and manage various web and mobile projects, using the latest technologies around. I regularly outsource work, and also develop.

Updated on November 28, 2020

Comments

  • BCLtd
    BCLtd over 3 years

    I'm trying to update my PHP (currently v:5.3.3 to the latest stable PHP build) but it's not playing ball and it's saying there is nothing to update.

    Any help would be useful.

    Keeps saying:

    No Packages marked for Update

  • BCLtd
    BCLtd over 10 years
    Thanks, this is much appreciated!
  • jbrahy
    jbrahy about 10 years
    webtatic.com also offers php 5.5/5.4 by installing this rpm. rpm -Uvh mirror.webtatic.com/yum/el6/latest.rpm
  • Matt Browne
    Matt Browne over 9 years
    In case anyone else out there needs to do this upgrade on CentOS 5, use this command instead: rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
  • Matt Browne
    Matt Browne over 9 years
    See also shayanderson.com/linux/… (and note that you can leave off the .x86_64 suffixes from the package names; it will default to your current architecture [which might be i386, not x86_64]).
  • Liam
    Liam over 9 years
    As a newcomer to CentOS, how do I know these repos are trustworthy?
  • TMH
    TMH over 9 years
    I get no Package php54w error. I actually get the same error for 55 and 56 too. Any idea how I can fix that?
  • Jacob Budin
    Jacob Budin over 9 years
    @Liam Practically speaking, you cannot be assured any software is trustworthy. In this case, if you believe the PHP source code is trustworthy but this respository may not be, you can compile the products yourself (in the same manner as the repository owner) and compare the hashes (e.g., with sha1sum) to see whether they are equal.
  • Muhaimin
    Muhaimin over 9 years
    as for centOs 7, here you go http://mirror.webtatic.com/yum/el7/epel-release.rpm
  • Timo002
    Timo002 over 9 years
    That didn't work at all for me on CentoOS 6.6. Luckely I made a snapshot before!
  • TheRealJAG
    TheRealJAG about 9 years
    I ran into the same problem with the conflict on CentOS 6.0 64bit, however running yum install php54w-mysql fixed the problem.
  • Sean Werkema
    Sean Werkema almost 9 years
    Downvoting because this mirror is no longer valid; webtactic.com now points to a parked domain. EDIT: It appears they have a broken redirect; it's all https now. Please update your links!
  • Sean Werkema
    Sean Werkema almost 9 years
    No, it's a broken URL; https requests time out, and http redirects to a parked domain. There's something seriously wrong with webtactic.com. Do you know of any other valid mirrors?
  • Simon East
    Simon East almost 9 years
    Hi @SeanWerkema - I've just tested in my browser and both webtatic.com and mirror.webtatic.com seem to still be available. Can you retest?
  • Lucha Laura Hardie
    Lucha Laura Hardie over 8 years
    I made the mistake of thinking that the folder in the URL named "el6" had a number one in it, as opposed to the letter "l". Make sure you are entering a letter "l" and not "1". That worked for me.
  • djowinz
    djowinz about 8 years
    So apparently my edit was rejected for no apparent reason. So if in any case your yum installation fails to reference the webtatic repo which in my case did you can call the repo again by appending --enablerepo=webtatic.
  • Miguel Tavares
    Miguel Tavares about 8 years
    This worked for me. I have been trying 100s of different solutions, finally I found yours. Thanks!
  • Areeb Soo Yasir
    Areeb Soo Yasir over 7 years
    This is good information but everyone should use caution as unfortunately a lot of functions have been deprecated as you move to newer PHP versions. This could mean without thorough testing that you break your application and will only find out the hard way later on. At the very minimum a test-plan should be made and error logs should be watched for functions that do not exist anymore.
  • ESP32
    ESP32 about 7 years
    I get Error: php56u conflicts with php-5.4.16-42.el7.x86_64
  • Ruben Estrada
    Ruben Estrada over 6 years
    just wanted to point out that the repo suggested in this answer (webatic) is not recommended by the centos community wiki (see: wiki.centos.org/AdditionalResources/Repositories). They say " IUS or SCL are better alternatives."
  • Simon East
    Simon East over 6 years
    Thanks @RubenEstrada - feel free to edit my answer with the necessary commands to use the better repos - preferably well-tested to ensure they work as expected. ;-)
  • Phyllis Sutherland
    Phyllis Sutherland about 6 years
    for soap: yum install php56w-soap
  • Robert Dundon
    Robert Dundon almost 6 years
    Quite a bit of time later since this answer, but I see epel-release-latest-7.noarch.rpm is downloaded, but is it installed?
  • Robert Dundon
    Robert Dundon almost 6 years
    @JacobBudin True, but I think healthy skepticism of unofficial repos is a good thing
  • Bonfix Ngetich
    Bonfix Ngetich almost 6 years
    To install use rpm -Uvh ius-release*.rpm
  • miken32
    miken32 over 5 years
    I feel like this has been pretty well covered in other answers over the past 5 years.
  • SyntaxGoonoo
    SyntaxGoonoo over 5 years
    The above answers don't include steps for upgrading CentOS 6 to PHP 7. So I have added an answer for this.