Site icon Ryadel

How to downgrade PHP version on Linux CentOS

How to downgrade PHP version on Linux CentOS
For a detailed guide about how to install PHP 7 on CentOS, read here.

PHP 7.2 release introduced many breaking changes that could prevent some of your application from working properly. Among the many backward-incompatible improvements, perhaps the most  crippling one is what they called Warn when counting non-countable types.

Here's what it does in a nutshell (from php.net official docs):

An E_WARNING will now be emitted when attempting to count() non-countable types (this includes the sizeof() alias function).

 

[...]

 

Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d

At a first glance this might seem trivial, but there's a high chance that - if you see such warning - you'll have to deal with some minor or major issues that could prevent your web app from working properly. If you own the code - or if you're willing to perform the required chance to the third party code - you'll be eventually able to fix that by yourself, but if you don't want to (or cannot) do that, you should seriously consider downgrading your PHP to a more compatible release, such as PHP 7.1.

In order to do that, you have to perform the following commands - assuming you're running a Linux CentOS 7.x machine with the Remi's RPM repositories installed: if you don't, read this post for further instructions. Before you do that, it can be wise to backup your /etc/php.ini  file and - if we're using the php-fpm FastCGI extension - the /etc/php-fpm.d/  folder.

  • Open a terminal window.
  • Identify the PHP packages you need to uninstall with the following command: rpm -qa |grep php .
  • Take a note and/or make a screenshot of all the package you need - as you'll have to reinstall them later on.
  • Remove the installed PHP 7.2 packages - along with all their dependencies - with the following command: yum remove php-*
  • Install the PHP 7.1 packages with the following command:
The above command is the most important one, as it tells yum what repository it should take into account (and which one(s) to skip) before the package lookup.
In the above example we're taking for granted that you already have the Remi's RPM repositories for PHP 7.1 and PHP 7.2 installed on your CentOS system: in case you don't, read here for instructions on how to install them. In case you're using different repos, you just need to replace remi-php71 with your PHP 7.1 repository and remi-php72 with the PHP 7.2 one.

Once done, you just have to restore our previous setup in the following way:

  • Restore your previous /etc/php.ini  file from the backup you made;
  • In case we're using the php-fpm FastCGI extension, you also have to restore your previous /etc/php-fpm.d/  folder from the backup and type the following commands to start-enable the php-fpm service:
That's it: you've just downgraded your PHP 7.2 to PHP 7.1!

Needless to say, you can use the same technique to roll-back to a previous version, such as PHP 7.0 or PHP 5.6: just be sure to use the --disablerepo  parameter to exclude the newer PHP repositories as explained above.

 

 

 

Exit mobile version