How to Install PHP 7.4 on Ubuntu 20.04/19.04/18.04
1 min read

How to Install PHP 7.4 on Ubuntu 20.04/19.04/18.04

PHP is a popular server scripting language that is widely used to create interactive websites and web applications. This language's roots began in 1994. In this tutorial we will show you how you can install PHP on your elected Ubuntu version.
How to Install PHP 7.4 on Ubuntu 20.04/19.04/18.04

PHP is a popular server scripting language that is widely used to create interactive websites and web applications. This language's roots began in 1994.

How to Install PHP 7.4 on Ubuntu 20.04

You'll first want to begin by updating apt with the below command.

sudo apt update

Next, install the PHP packages and dependencies.

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

After the installation has finished you can confirm the PHP version that is in use.

php --version

You should see some results like below.

PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

How to Install PHP 7.4 on Ubuntu 19.04/18.04

Installing PHP 7.4 on Ubuntu 19.04/18.04 is a bit different than 20.04. To get started, update apt and add the required repositories.

sudo apt-get update
sudo apt -y install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

And begin the install.

sudo apt install php7.4

After the install is complete, you can check the version that is installed and in use.

php -v

How to Install PHP for Nginx

By default, PHP on Ubuntu is installed for Apache2 use. If you are interested in using Nginx for your web server, follow the below commands.

To start, we will need to disable Apache2.

sudo systemctl disable --now apache2

With Apache2 disabled, we can now install PHP for Nginx.

sudo apt-get install nginx php7.4-fpm

After the install, you can confirm if both services (PHP and Nginx) are running without any issues.

systemctl status php7.4-fpm nginx


Should you have any trouble, send me a message and I'll do my best to help out.

Enjoying these posts? Subscribe for more