20

I need to downgrade PHP on one of my VMs from 7.2 to 7.1 on Ubuntu 16.0.4. The last time I tried to remove just PHP and replace it with a different version, I had all kinds of issues with Apache and MySQL. Is there a quick way to downgrade PHP from 7.2 to 7.1 without having to fully reinstall and configure Apache (latest version as of this writing) and everything else on the server?

I have to downgrade due to bad information I received from a software vendor that claims their application runs on PHP 7.2. Turns out it must have 7.1.

I tried looking for info about how to downgrade from 7.2 to 7.1, but only get 'upgrade' results.

Thank you for your help.

  • 1
    How did you get PHP 7.2 to begin with? – Michael Hampton Feb 5 '18 at 17:31
  • Update: I used sudo add-apt-repository ppa:ondrej/php to install PHP 7.2.x – Pegues Feb 5 '18 at 17:33
33

Below is a description of what I did. I hope this information can help someone else:

I installed PHP 7.1 along side PHP 7.2. I also installed most of the needed extensions for PHP 7.1. I then did a2dismod php7.2 and a2enmod php7.1 so that I could switch over to PHP 7.1 while keeping 7.2 still installed on the server. Most of my sites work after making the switch. The only site that doesn't seem to be working is a Joomla site. The full list of commands I ran are below:

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

sudo apt-get install php7.1

sudo apt-get install php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm

sudo a2dismod php7.2

sudo a2enmod php7.1

sudo service apache2 restart
  • 1
    I am also in the same situation but even after disabling 7.2 module, if I type php -v, it still shows php7.2. Any idea? – khichar.anil Apr 3 '18 at 23:52
  • 1
    I too have the same thing. Even though PHP 7.1 is currently enabled on my server, typing php -v shows PHP 7.2.2. However, if I load phpinfo() in my browser, it will show the correct version, 7.1.13. Have you tried reviewing a file with phpinfo() ? – Pegues Apr 4 '18 at 0:17
  • See my comment below. It will change the default php path. – khichar.anil Apr 4 '18 at 1:30
  • 1
    A helpful article tecadmin.net/switch-between-multiple-php-version-on-ubuntu – CrandellWS Apr 28 '18 at 17:57
  • @CrandellWS thanks for the share. Certainly helpful information. – Pegues Apr 30 '18 at 12:44
18

for display enabled php version in terminal by php -v. we need to set update cli version of php. use below command to update php cli version

// change terminal (cli) version (7.2 to 7.1)
sudo update-alternatives --set php /usr/bin/php7.1
12

@pegues: Your above mentioned method worked well for apache to switch the different version. By running following commands will change the php from terminal as well. Actually you just need to change the symlink to the desired PHP version.

sudo rm /usr/bin/php

sudo ln -s /usr/bin/php7.1 /usr/bin/php
1

This is what I did:

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

sudo apt-get install php7.1

sudo apt-get install php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm

sudo rm /usr/bin/php

sudo ln -s /usr/bin/php7.1 /usr/bin/php

And to confirm that you have the php 7.1 type the following command

php --ini |grep Loaded

it should return the following response

Loaded Configuration File:         /etc/php/7.1/cli/php.ini

if you are using laravel for some reason then modify your fpm.service to point to the 7.1 version and then restart it as well

sudo systemctl restart php7.1-fpm.service

sudo service nginx restart

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.