In this tutorial we will learn to install PHP 8.0 on Ubuntu 20.04 LTS using PPA. PHP 8.0 is the latest version of php and it have many upgrades. Installation process is same as How to install PHP on Ubuntu? or How to Install multiple/different version of PHP?
Step 1 : Add ppa:ondrej/php to Ubuntu system
Open the terminal or ssh connection and then type
//for <= ubunt 12.04
sudo apt install python-software-properties
//for >12.04
sudo apt install software-properties-common
Then install ppa:ondrej
sudo add-apt-repository ppa:ondrej/php
Output:
Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.
Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa
You can get more information about the packages at https://deb.sury.org
IMPORTANT: The <foo>-backports is now required on older Ubuntu releases.
BUGS&FEATURES: This PPA now has a issue tracker:
https://deb.sury.org/#bug-reporting
CAVEATS:
1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline
or ppa:ondrej/nginx
Step 2 : Update the system
sudo apt-get update
Step 3 : Check php versions available
sudo apt show php
Output :
Package: php
Version: 2:8.0+84+ubuntu20.04.1+deb.sury.org+1
Priority: optional
Section: php
Source: php-defaults (84+ubuntu20.04.1+deb.sury.org+1)
Maintainer: Debian PHP Maintainers <team+pkg-php@tracker.debian.org>
Installed-Size: 13.3 kB
Depends: php8.0
Download-Size: 6960 B
APT-Sources: http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
open source general-purpose scripting language that is especially suited
for web development and can be embedded into HTML.
.
This package is a dependency package, which depends on latest stable
PHP version (currently 8.0).
Package: php
Version: 2:7.4+75
Priority: optional
Section: php
Source: php-defaults (75)
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian PHP Maintainers <team+pkg-php@tracker.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 13.3 kB
Depends: php7.4
Download-Size: 2712 B
APT-Manual-Installed: yes
APT-Sources: http://ap-south-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
open source general-purpose scripting language that is especially suited
for web development and can be embedded into HTML.
.
This package is a dependency package, which depends on latest stable
PHP version (currently 7.4).
We can now install php 8.
Step 4 : Install different version of PHP
For apache you can now install any version
$ sudo apt install php5.6 [PHP 5.6]
$ sudo apt install php7.0 [PHP 7.0]
$ sudo apt install php7.1 [PHP 7.1]
$ sudo apt install php7.2 [PHP 7.2]
$ sudo apt install php7.3 [PHP 7.3]
$ sudo apt install php7.4 [PHP 7.4]
$ sudo apt install php8.0 [PHP 8.0]
For Nginx
$ sudo apt install php5.6-fpm [PHP 5.6]
$ sudo apt install php7.0-fpm [PHP 7.0]
$ sudo apt install php7.1-fpm [PHP 7.1]
$ sudo apt install php7.2-fpm [PHP 7.2]
$ sudo apt install php7.3-fpm [PHP 7.3]
$ sudo apt install php7.4-fpm [PHP 7.4]
$ sudo apt install php8.0-fpm [PHP 8.0]
In this way you can install any version. so finally we are installing PHP 8.0 with some basic important modules
sudo apt install php8.0
Step 5 : Check installed versions of PHP
sudo update-alternatives --config php
Output :
There are 3 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/php8.0 80 auto mode
1 /usr/bin/php7.0 70 manual mode
2 /usr/bin/php7.4 74 manual mode
3 /usr/bin/php8.0 80 manual mode
Press <enter> to keep the current choice[*], or type selection number:
As we can see PHP 8.0 is installed and we have selected it as default by pressing 1.
Install modules for any version
Simply type the version you want to install then type tab
to show available module for specific module.
Example:
$ sudo apt install php8.0
php8.0 php8.0-inotify php8.0-rrd
php8.0-amqp php8.0-interbase php8.0-smbclient
php8.0-apcu php8.0-intl php8.0-snmp
php8.0-ast php8.0-ldap php8.0-soap
php8.0-bcmath php8.0-lz4 php8.0-solr
php8.0-bz2 php8.0-mailparse php8.0-sqlite3
php8.0-cgi php8.0-maxminddb php8.0-ssh2
php8.0-cli php8.0-mbstring php8.0-swoole
php8.0-common php8.0-mcrypt php8.0-sybase
php8.0-curl php8.0-memcache php8.0-tidy
php8.0-dba php8.0-memcached php8.0-uopz
php8.0-decimal php8.0-mongodb php8.0-uploadprogress
php8.0-dev php8.0-msgpack php8.0-uuid
php8.0-ds php8.0-mysql php8.0-vips
php8.0-enchant php8.0-oauth php8.0-xdebug
php8.0-fpm php8.0-odbc php8.0-xhprof
php8.0-gd php8.0-opcache php8.0-xml
php8.0-gearman php8.0-pcov php8.0-xmlrpc
php8.0-gmagick php8.0-pgsql php8.0-xsl
php8.0-gmp php8.0-phpdbg php8.0-yac
php8.0-gnupg php8.0-protobuf php8.0-yaml
php8.0-grpc php8.0-pspell php8.0-zip
php8.0-http php8.0-psr php8.0-zmq
Example:
sudo apt install php8.0-cli php8.0-xml php8.0-mysql libapache2-mod-php8.0
here we are installing few modules for PHP 8.
Set Default PHP Version in Ubuntu
Now, we have installed multiple versions of php but at a time we can use one so let’s choose one PHP version
Step 1 : To check available versions of PHP
sudo update-alternatives --config php
Output:
There are 2 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/php7.4 74 auto mode
1 /usr/bin/php7.0 70 manual mode
2 /usr/bin/php7.4 74 manual mode
Press <enter> to keep the current choice[*], or type selection number:
Enter the number and you have successfully changed the version of PHP.
Step 2 : Check version of php
$ php -v
Related