Install PHP 7.4 on Ubuntu 18.04

In this tutorial, you will learn how to install PHP 7.4 on Ubuntu 18.04. PHP is a widely used general-purpose scripting language that is particularly well suited for web development. It was one of the first server-side languages to be integrated into HTML, making it simple to add functionality to web sites without accessing data from separate files. PHP is used in most web from your blog to the world’s most popular websites, and it’s fast, adaptable, and pragmatic.

How to Install PHP 7.4 on Ubuntu 18.04

  • First and foremost, we must ensure that our system is up to date. Run the following command to update and upgrade.
sudo apt update
sudo apt upgrade

Add PHP PPA Repository on Ubuntu 18.04

  • We must first install the required packages before we can add a new repository.
sudo apt -y install software-properties-common
  • Run this command to add the ondrej/php repository.
sudo add-apt-repository ppa:ondrej/php

Sample output

Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP ( for Supported Ubuntu 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:

You can get more information about the packages at

IMPORTANT: The -backports is now required on older Ubuntu releases.

BUGS&FEATURES: This PPA now has a issue tracker:

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

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly:

WARNING: add-apt-repository is broken with non-UTF-8 locales, see for workaround:

# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
 More info:
Press [ENTER] to continue or Ctrl-c to cancel adding it.

Hit:1 focal InRelease
Get:2 focal-security InRelease [114 kB]
Hit:3 focal InRelease
Get:4 focal-updates InRelease [114 kB]
Get:5 focal InRelease [23.9 kB]
Get:6 focal-security/main amd64 DEP-11 Metadata [40.6 kB]
Get:7 focal-security/universe amd64 DEP-11 Metadata [66.2 kB]
Get:8 focal/main i386 Packages [34.4 kB]
Get:9 focal-security/multiverse amd64 DEP-11 Metadata [2,464 B]
Get:10 focal-backports InRelease [108 kB]
Get:11 focal/main amd64 Packages [101 kB]
Get:12 focal-updates/main amd64 Packages [1,581 kB]
Get:13 focal/main Translation-en [33.6 kB]
Get:14 focal-updates/main i386 Packages [605 kB]
Get:15 focal-updates/main amd64 DEP-11 Metadata [279 kB]
Get:16 focal-updates/main amd64 c-n-f Metadata [14.7 kB]
Get:17 focal-updates/universe i386 Packages [668 kB]
Get:18 focal-updates/universe amd64 Packages [904 kB]
Get:19 focal-updates/universe amd64 DEP-11 Metadata [390 kB]
Get:20 focal-updates/multiverse amd64 DEP-11 Metadata [940 B]
Get:21 focal-backports/main amd64 DEP-11 Metadata [8,004 B]
Get:22 focal-backports/universe amd64 DEP-11 Metadata [23.7 kB]
Fetched 5,113 kB in 20s (256 kB/s)                       
Reading package lists... Done
  • Next, update the system package list on newly added repositories before installing PHP 7.4 on Ubuntu 18.04.

Install PHP 7.4 on Ubuntu 18.04

  • Run the command below to update the package list on newly added repositories.
sudo apt update
  • After updating, run the following command to install PHP 7.4 on Ubuntu 18.04
sudo apt -y install php7.4
  • Alternatively you can run the following command to install PHP 7.4 with its modules
sudo apt -y install php7.4-fpm php7.4-bcmath php7.4-curl php7.4-gd php7.4-mbstring php7.4-mysql php7.4-xml php7.4-zip
  • Verify PHP version installed using the command below.
php -v

Sample output

PHP 7.4.28 (cli) (built: Feb 17 2022 16:06:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies
  • You have reached the end of the article, Congratulations. You have learned how to Install PHP 7.4 on Ubuntu 18.04.

Other Tutorials

Install WordPress with LAMP Stack on Ubuntu 22.04

Install WordPress with LEMP Stack on Ubuntu 22.04

Install htop command on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment