How To Install Latest PHP on Ubuntu 20.04

PHP powered many top websites in the world such as Wikipedia and WordPress. Every Linux distro had PHP repository which makes it easy to install and run PHP scripts. In Ubuntu 20.04 the PHP version is 7.4 and there’s no plan to add PHP 8.0. So we’ll need to use the third-party repository.

Depend on your application it may require PHP 7.4 or any other version, that not a problem because in Linux we can run multiple versions of PHP without any problem.

Let’s start installing PHP 7.4 and 8.0 on Ubuntu 20.04

PHP 7.4

PHP 7.4 coming with the default Ubuntu 20 repository, which can be installed directly using apt package manager.

sudo  apt-get install php7.4 php7.4-cli php7.4-common php7.4-gd php7.4-xmlrpc php7.4-fpm \
        php7.4-curl php7.4-intl php-imagick php7.4-mysql php7.4-zip php7.4-xml \
        php7.4-mbstring php7.4-bcmath php7.4-sqlite3 -y

for the other extension search using

sudo apt search php-7.4

for example we’re looking for xmlrpc for PHP 7.4, using grep to filter the result.

sudo apt search php-7.4 | grep xmlrpc

xmrpc php on ubuntu
then install using

sudo apt install php7.4-xmlrpc

PHP 8.0

The latest stable version of PHP is 8.0. To install this version on Ubuntu 20.04, we need a third-party repository that is preferable to installing from source code, which takes a lot of time and time consuming to maintenance when a new version comes.

1. Install dependency

sudo apt install software-properties-common apt-transport-https lsb-release ca-certificates wget -y

2. Install Sury Repository

sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt update

3. Install PHP 8.0

sudo apt-get install php8.0 php8.0-cli php8.0-common php8.0-gd php8.0-xmlrpc php8.0-fpm \
        php8.0-curl php8.0-intl php-imagick php8.0-mysql php8.0-zip php8.0-xml \
        php8.0-mbstring php8.0-bcmath php8.0-sqlite3 -y

Leave a Reply