How to Downgrade and Upgrade PHP 7.0 to PHP 7.1 or PHP 7.2 or PHP 7.3 on Ubuntu VestaCP
In this tutorial I’ll show you how to upgrade PHP 7.0 which is by default installed by Vesta CP during installation to PHP 7.1.xx or 7.2.xx or 7.3.xx latest on Ubuntu server, I’ve personally tested all php version i.e. 7.1, 7.2 and 7.3 before writing this tutorial and its just working fine without any issue hence it is safe to upgrade to PHP 7.1 or PHP 7.2 under vestacp or in Ubuntu/Debian.
Why upgrade to php 7.1, 7.2 or 7.3? – Because it will give you security & performance boost + KICK, since WordPress or supported scripts will load much faster and uses less resources.
Package needed for the installation, you need to install software-properties-common :
apt-get install software-properties-common
For Apache mod_php :
For PHP 7.1 Upgrade :
First you need to add Ondrejs PPA :
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
if you get : “‘ascii’ codec can’t decode byte” run this command :
export LANG=C.UTF-8
then run this commands :
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
Installing PHP 7.1 :
apt-get install libapache2-mod-php7.1 php7.1 php7.1-bcmath php7.1-bz2 php7.1-cgi php7.1-cli php7.1-common php7.1-curl php7.1-dba php7.1-dev php7.1-enchant php7.1-fpm php7.1-gd php7.1-gmp php7.1-imap php7.1-interbase php7.1-intl php7.1-json php7.1-ldap php7.1-mbstring php7.1-mcrypt php7.1-mysql php7.1-odbc php7.1-opcache php7.1-pgsql php7.1-phpdbg php7.1-pspell php7.1-readline php7.1-recode php7.1-snmp php7.1-soap php7.1-sqlite3 php7.1-sybase php7.1-tidy php7.1-xml php7.1-xmlrpc php7.1-xsl php7.1-zip
After installation disable php 7.0 module in order to activate the php7.1 module :
a2dismod php7.0 a2enmod php7.1
After you enabled the new php version module restart apach2 service :
service apache2 restart
For PHP 7.2 Upgrade :
First you need to add Ondrejs PPA (if you installed before then you can skip the PPA adding step) :
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
if you get : “‘ascii’ codec can’t decode byte” run this command :
export LANG=C.UTF-8
then run this commands :
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
Installing PHP 7.2 :
apt-get install libapache2-mod-php7.2 php7.2 php7.2-bcmath php7.2-bz2 php7.2-cgi php7.2-cli php7.2-common php7.2-curl php7.2-dba php7.2-dev php7.2-enchant php7.2-fpm php7.2-gd php7.2-gmp php7.2-imap php7.2-interbase php7.2-intl php7.2-json php7.2-ldap php7.2-mbstring php7.2-mysql php7.2-odbc php7.2-opcache php7.2-pgsql php7.2-phpdbg php7.2-pspell php7.2-readline php7.2-recode php7.2-snmp php7.2-soap php7.2-sqlite3 php7.2-sybase php7.2-tidy php7.2-xml php7.2-xmlrpc php7.2-xsl php7.2-zip
For PHP 7.3 Upgrade :
First you need to add Ondrejs PPA (if you installed before then you can skip the PPA adding step) :
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
if you get : “‘ascii’ codec can’t decode byte” run this command :
export LANG=C.UTF-8
then run this commands :
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
Installing PHP 7.3 :
apt-get install libapache2-mod-php7.3 php7.3 php7.3-bcmath php7.3-bz2 php7.3-cgi php7.3-cli php7.3-common php7.3-curl php7.3-dba php7.3-dev php7.3-enchant php7.3-fpm php7.3-gd php7.3-gmp php7.3-imap php7.3-interbase php7.3-intl php7.3-json php7.3-ldap php7.3-mbstring php7.3-mysql php7.3-odbc php7.3-opcache php7.3-pgsql php7.3-phpdbg php7.3-pspell php7.3-readline php7.3-recode php7.3-snmp php7.3-soap php7.3-sqlite3 php7.3-sybase php7.3-tidy php7.3-xml php7.3-xmlrpc php7.3-xsl php7.3-zip
After installation disable php 7.0 module in order to activate the php7.2 module :
a2dismod php7.0 a2enmod php7.2
After you enabled the new php version module restart apach2 service :
service apache2 restart
EXTRAS
To upgrade php7.1 to php 7.2 simply run this commands :
a2dismod php7.1 a2enmod php7.2 service apache2 restart
To upgrade php7.2 to php 7.3 simply run this commands :
a2dismod php7.2 a2enmod php7.3 service apache2 restart
OR Downgrade php 7.2 to php 7.0 :
a2dismod php7.2 a2enmod php7.0 service apache2 restart
Downgrade php 7.2 to php 7.1 :
a2dismod php7.2 a2enmod php7.1 service apache2 restart
Downgrade php 7.3 to php 7.1 :
a2dismod php7.3 a2enmod php7.1 service apache2 restart
Downgrade php 7.3 to php 7.2 :
a2dismod php7.3 a2enmod php7.2 service apache2 restart
To install/downgrade php 5.6 and switch from PHP 7.x to php 5.6 :
apt-get install libapache2-mod-php5.6 php5.6 php5.6-bcmath php5.6-bz2 php5.6-cgi php5.6-cli php5.6-common php5.6-curl php5.6-dba php5.6-dev php5.6-enchant php5.6-fpm php5.6-gd php5.6-gmp php5.6-imap php5.6-interbase php5.6-intl php5.6-json php5.6-ldap php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-odbc php5.6-opcache php5.6-pgsql php5.6-phpdbg php5.6-pspell php5.6-readline php5.6-recode php5.6-snmp php5.6-soap php5.6-sqlite3 php5.6-sybase php5.6-tidy php5.6-xml php5.6-xmlrpc php5.6-xsl php5.6-zip
Then switch to php 5.6 :
a2dismod php7.x a2enmod php5.6 service apache2 restart
replace x with 0,1,2,3
upgrade php 5.6 to 7.x :
a2dismod php5.6 a2enmod php7.x service apache2 restart
replace x with 0,1,2,3