Skip to content

Instantly share code, notes, and snippets.

@xeptore
Last active February 5, 2021 11:07
Show Gist options
  • Save xeptore/a7200e21d239e2a7c51fa035b1b55ec7 to your computer and use it in GitHub Desktop.
Save xeptore/a7200e21d239e2a7c51fa035b1b55ec7 to your computer and use it in GitHub Desktop.
How to downgrade/upgrade PHP versions on Ubuntu-based linux distros

Add Repo

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get upgrade

Install PHP5.6

sudo apt-get install php5.6 php5.6-cli php5.6-common libapache2-mod-php5.6 php5.6-mysql php5.6-fpm php5.6-curl php5.6-gd php5.6-bz2 php5.6-mcrypt php5.6-json php5.6-tidy php5.6-mbstring php5.6-intl php-redis php-memcached php-gettext php-xdebug

Install PHP7.0

sudo apt-get install php7.0 php7.0-cli php7.0-common libapache2-mod-php7.0 php7.0-mysql php7.0-fpm php7.0-curl php7.0-gd php7.0-bz2 php7.0-mcrypt php7.0-json php7.0-tidy php7.0-mbstring php7.0-intl php-redis php-memcached php-gettext php-xdebug

Install PHP7.1

sudo apt-get install php7.1 php7.1-cli php7.1-common libapache2-mod-php7.1 php7.1-mysql php7.1-fpm php7.1-curl php7.1-gd php7.1-bz2 php7.1-mcrypt php7.1-json php7.1-tidy php7.1-mbstring php7.1-intl php-redis php-memcached php-gettext php-xdebug

Switch versions

Upgrade:

From PHP5.6 to PHP7.0:

Apache:

sudo a2dismod php5.6; sudo a2enmod php7.0; sudo service apache2 restart

CLI:

sudo update-alternatives --set php /usr/bin/php7.0
From PHP7.0 to PHP7.1:

Apache:

sudo a2dismod php7.0; sudo a2enmod php7.1; sudo service apache2 restart

CLI:

sudo update-alternatives --set php /usr/bin/php7.1

Downgrade:

From PHP7.1 to PHP7.0:

Apache:

sudo a2dismod php7.1; sudo a2enmod php7.0; sudo service apache2 restart

CLI:

sudo update-alternatives --set php /usr/bin/php7.0
From PHP7.0 to PHP5.6:

Apache:

sudo a2dismod php7.0; sudo a2enmod php5.6; sudo service apache2 restart

CLI:

sudo update-alternatives --set php /usr/bin/php5.6

Update:

If after you follow the instructions you face this situation that PHP7 running despite You have disabled php7.0 apache module still phpinfo was showing php7 using fastCGI, you may need to disable the proxy_fcgi apache module:

sudo a2dismod proxy_fcgi proxy; sudo service apache2 restart

Link to this question on askubuntu.com:
https://askubuntu.com/a/762161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment