How to Install PHP 7.4 on Ubuntu?. Welcome to today’s guide on how to install PHP 7.4 on Ubuntu 20.04/18.04/16.04 Linux. The PHP release 7.4.0 has been made available for the general public and for use in Production environments.

PHP is a popular server scripting language known for creating dynamic and interactive Web pages. PHP is widely-used programming language in the Web. Use the steps below to install PHP 7.4 on Ubuntu 20.04/18.04/16.04.

Let’s consider the two installations for PHP 7.4 on Ubuntu 20.04 / Ubuntu 18.04 and Ubuntu 16.04.

Install PHP 7.4 on Ubuntu 20.04

NOTE: Ubuntu 20.04 ships with PHP 7.4 in its upstream repositories. Just install it and the extensions you with the apt package manager.

sudo apt update
sudo apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath

Confirm PHP version:

$ php --version
PHP 7.4.3-4ubuntu2.19 (cli) (built: Jun 27 2023 15:49:59) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3-4ubuntu2.19, Copyright (c), by Zend Technologies

Listing all loaded PHP modules:

$ php -m

Install PHP 7.4 on Ubuntu 18.04|16.04

For the other editions of Ubuntu, use the process below:

Step 1: Add PHP PPA Repository

We’ll PPA repository which has the latest build packages of PHP. But first install dependent packages.

sudo apt update
sudo apt -y install software-properties-common

Add the repos:

sudo add-apt-repository ppa:sergey-dryabzhinsky/php74
sudo add-apt-repository ppa:sergey-dryabzhinsky/php7-modules
sudo add-apt-repository ppa:sergey-dryabzhinsky/backports
sudo add-apt-repository ppa:sergey-dryabzhinsky/packages

Step 2: Install PHP 7.4

Install PHP 7.4 on Ubuntu using the command:

sudo apt -y install php7.4

Check version installed:

$ php -v
PHP 7.4.33-SergeyD/6.1 (cli) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Use the next command to install additional packages:

sudo apt install php7.4-xxx

Example:

sudo apt install php74p-mod-{mysql,bcmath,bz2,gd,intl,mbstring,zip,json}

PHP configurations related to Apache is stored in /etc/php74/cli/php.ini

Confirm PHP version: