How to Install PHP 8.0 & PECL Extensions in Ubuntu 20.04, 18.04, 16.04

Want to install PHP 8.0 as well as many PECL extensions in your Ubuntu Server? Well there’s a well trusted PPA that contains the packages for all current Ubuntu releases.

Ondřej Surý, a Debian Developer who maintains the official PHP packages in Debian, is maintaining an Ubuntu PPA that contains the latest PHP 5.6, PHP 7.0, PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, and PHP 8.0 packages as well as PECL extensions for all current Ubuntu releases.

1.) Simply open terminal or connect to your remote Ubuntu server, and run command to make sure software-properties-common is installed:

sudo apt install software-properties-common

2.) Then run command to add the php PPA repository by running command:

sudo add-apt-repository ppa:ondrej/php

For non-UTF-8 locales, run LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php

Advertisements

3.) If you are using php-gearman, you need to run command to add the gearman PPA:

sudo add-apt-repository ppa:ondrej/pkg-gearman

I’m using Nginx web server, and it’s recommended to add the Nginx stable PPA instead:

sudo add-apt-repository ppa:ondrej/nginx

If you’re using Apache2, adding the apache2 PPA is recommended:

sudo add-apt-repository ppa:ondrej/apache2

4.) Finally refresh system package cache and install php 8.0 packages via command:

sudo apt update

sudo apt install php8.0-fpm libapache2-mod-php8.0 php8.0-mysql php8.0-xml

There are also many other packages available, e.g., php8.0-amqp, php8.0-apcu, php8.0-memcache, php8.0-memcached, and more. Just add or remove package names after “sudo apt install” depends what you need.

In all previous commands, you can replace php8.0 with php7.4, php7.3, php7.2, php7.0, or php5.6 to install a specify version of PHP packages

Uninstall PHP:

To remove an Ubuntu PPA, add --remove flag in adding PPA command. For instance, remove php PPA via command:

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

Instead of removing Ubuntu PPA, you can also purge PPA which also downgrade installed packages to the stock version in Ubuntu repositories.

sudo apt install ppa-purge && sudo ppa-purge ppa:ondrej/php

To remove a php package, simply run command:

sudo apt remove Package_Name_Here