How to install PHP 7.4 on Ubuntu 18.04

Overview

In this tutorial, you will learn how to install PHP 7.4 onto Ubuntu 18.04 for better performance in your applications.

The Ubuntu 18.04 package repository limits which version of packages are available. Major updates are reserved for major OS releases, which is how to operating system remains stable. Packages are only updated with bug and security releases.

In order to install later versions of packages like PHP we need to add a new repository. For Ubuntu, the most common way of adding community managed repositories is with Launchpad’s PPA support (Personal Package Archives).

A PPA for Ubuntu is available that specializes in PHP, by providing major new releases to older version of the operating system.

Add PPA for PHP

A PPA by the name of ondrej/php offers PHP packages for Ubuntu. It provides major releases of PHP for older Ubuntu versions, which is how you will install PHP 7.4 onto the operating system.

Add the PPA to your package repository list.

sudo add-apt-repository ppa:ondrej/php

Update your repository cache to ensure packages from the ondrej/php repository are available.

sudo apt-get update

Install PHP 7.4

To install PHP version from the PPA we use the following package name convetion phpX.X. For example, to install PHP 7.4 you would put php7.4 as the package name.

sudo apt-get install php7.4

Installing PHP 7.4 Modules

There are a lot of modules available for PHP, from connecting to a MySQL database server to parsing XML files. Each module supports a specific version of PHP, and in order to install the modules for PHP 7.4 we must specify the version of PHP.

For example, to install the MySQL module for PHP 7.4 you would need to run the following command.

sudo apt-get install php7.4-mysql

Conclusion

In this tutorial, you learned how to install PHP 7.4 on Ubuntu using PPAs. You also learned how to install PHP 7.4 modules to support applications like WordPress.

PPA’s are extremely helpful with installing software not officially supported by an Ubuntu release’s package repository. By expanding on the software available we are able to more easily install packages that can’t be found.

While PPAs do offer us extended packages, they are also managed by a third-party. As such, you should always verify the contents of the packages you install, and scanning them for malicious code.