SIGN IN / UP
    opened image

    This article will guide you through updating and downgrading the PHP version, especially when your website requires a different PHP version than the one installed on the server. For example, if your CMS WordPress needs PHP 7.3, but the server has PHP 5.6.


    Preparation: First, install the repositories needed to install PHP. Use the following commands:

    yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    yum install yum-utils

    We've set up the base for managing PHP versions. Currently, PHP 5.6 is installed. In this article, we'll update it to 7.4 and then downgrade it back to 5.6.

    Warning: Upgrading PHP may affect the functionality of PHPMyAdmin and other applications tied to a specific PHP version.


    Update: To update PHP, activate the repository with the new PHP version:

    yum-config-manager --enable remi-php74


    Replace '74' with your desired PHP version. Then, run the update command:

    yum update

    Confirm the installation of PHP 7.4 packages. Check the PHP version with:

    php -v

    You should see the updated version.

     

    Downgrade: To downgrade, install the PHP repositories and yum-utils (commands in the Preparation section).

    First, find out which modules are installed on the current PHP version:

    php -m


    Copy the list of modules; you'll need it when installing the new PHP version.


    Remove the old PHP version and its modules:

    yum remove php php-*


    Disable the repository for the current PHP version and enable the one you need (e.g., PHP 5.6):

    yum-config-manager --disable remi-php74 --enable remi-php56


    Install PHP and modules for the desired version:

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

    Check installed modules:

    php -m

    Compare with the modules from the old version. If any are missing, install them with:

    yum install php-module_name php-module_name php-module_name

     

    You've successfully downgraded PHP on CentOS 7.