Actions

Install Different Version of PHP on Ubuntu

From InfoTechPedia

Revision as of 21:33, 14 August 2020 by TomHutchison (talk | contribs) (Created page with "You can install different versions of PHP on Ubuntu. This will also show how to install the versions and use them on Virtualmin for different virtual servers on a Virtualmin/W...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

You can install different versions of PHP on Ubuntu. This will also show how to install the versions and use them on Virtualmin for different virtual servers on a Virtualmin/Webmin install.

Add the Repository

Ubuntu 16.06

Use the following on the command line.

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

Ubuntu 18.04

Use the following on the command line.

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

Additional Info

After the updates you can use sudo apt-get upgrade for Ubuntu 16.04 or sudo apt upgrade for Ubuntu 18.04. This should pull down the very latest version of PHP from the ondrej/php repository. Currently, as of this writing is PHP 7.4.

Install Specific Versions & Modules

Right now I am using the following. You can substitute 7.3 or 7.2 for 7.4. Just check the modules available per PHP version noted below.

Time to install.

Ubuntu 16.04

sudo apt-get install php7.4 php7.4-cli php7.4-common php7.4-cgi

Then the following modules (these are the ones I generally install):

sudo apt-get install php7.4-bcmath php7.4-bz2 php7.4-curl php7.4-dba php7.4-enchant php7.4-gd
php7.4-gmp php7.4-imap php7.4-interbase php7.4-intl php7.4-ldap php7.4-mbstring php7.4-mysql
php7.4-odbc php7.4-pgsql php7.4-pspell php7.4-snmp php7.4-soap php7.4-tidy php7.4-xml php7.4-xmlrpc 
php7.4-xsl php7.4-zip

Check your version. Usually, the highest version is available with:

user@YourServer:~$ php -v
PHP 7.4.9 (cli) (built: Aug  7 2020 14:29:10) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies
user@YourServer:~$ php7.3 -v
PHP 7.3.21-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Aug  7 2020 14:43:42) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.21, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.21-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
user@YourServer:~$ 

Check what modules are installed.
<pre>
user@YourServer:~$ php7.2 -m
[PHP Modules]
apc
apcu
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
enchant
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
imagick
imap
interbase
intl
json
ldap
libxml
mbstring
mcrypt
mysqli
mysqlnd
odbc
openssl
pcntl
pcre
PDO
pdo_dblib
PDO_Firebird
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
pspell
readline
recode
Reflection
session
shmop
SimpleXML
snmp
soap
sockets
sodium
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

user@YourServer:~$ 

Now check what modules are available.

user@YourServer:~$ sudo apt-cache search php7.4
php-amqp - AMQP extension for PHP
php-apcu - APC User Cache for PHP
php-geoip - GeoIP module for PHP
php-igbinary - igbinary PHP serializer
php-imagick - Provides a wrapper to the ImageMagick library
php-mongodb - MongoDB driver for PHP
php-msgpack - PHP extension for interfacing with MessagePack
php-oauth - OAuth 1.0 consumer and provider extension
php-redis - PHP extension for interfacing with Redis 
...truncated...
php7.4-soap - SOAP module for PHP
php7.4-sqlite3 - SQLite3 module for PHP
php7.4-sybase - Sybase module for PHP
php7.4-tidy - tidy module for PHP
php7.4-xml - DOM, SimpleXML, XML, and XSL module for PHP
php7.4-xmlrpc - XMLRPC-EPI module for PHP
php7.4-xsl - XSL module for PHP (dummy)
php7.4-zip - Zip module for PHP

Ubuntu 18.04

sudo apt install php7.4 php7.4-cli php7.4-common php7.4-cgi

Then I add the following modules as a start:

sudo apt-get install php7.4-bcmath php7.4-bz2 php7.4-curl php7.4-dba php7.4-enchant php7.4-gd
php7.4-gmp php7.4-imap php7.4-interbase php7.4-intl php7.4-ldap php7.4-mbstring php7.4-mysql
php7.4-odbc php7.4-pgsql php7.4-pspell php7.4-snmp php7.4-soap php7.4-tidy php7.4-xml php7.4-xmlrpc 
php7.4-xsl php7.4-zip