Hamsa K
Editor
4 min read | 6 months ago

How to Install PHP 7.4 on Ubuntu 18 04

How to Install PHP 7.4 on Ubuntu 18.04/19.04

Ubuntu 18.04 ships with PHP 7.2 as default PHP version.The latest PHP 7.4 version is officially released on November 28th, 2019.This latest version adds several new features.

Step 1: Add PPA repository

Run below commands to add repository 

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

once repository is added now you can install php

Step 2: Install php 7.4

root@ubuntu18:~# apt install php7.4
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-php7.4 libpcre2-8-0 php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php7.4 libpcre2-8-0 php-common php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline
0 upgraded, 9 newly installed, 0 to remove and 64 not upgraded.
Need to get 4,193 kB of archives.
After this operation, 18.1 MB of additional disk space will be used.
Do you want to continue? [Y/n]

press 'y' to install those all packages.

Now you can check php version like below

root@ubuntu18:~# php -v
PHP 7.4.2 (cli) (built: Jan 23 2020 11:21:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.2, Copyright (c), by Zend Technologies

you can check installed packages with following command

root@ubuntu18:~# apt list --installed | grep php

you can search for any additional php modules by using below command

root@ubuntu18:~# apt-cache search php7.4*

if you need additional packages install them as per your requirement

root@ubuntu18:~# apt install php7.4-gd php7.4-cli php7.4-mysql php7.4-xml php7.4-pgsql php7.4-soap php7.4-bcmath php7.4-curl php7.4-imap

For Debian9/10:

First we need to install below repository 

sudo apt install -y apt-transport-https lsb-release ca-certificates wget
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update

Now you can install php7.4 

apt install php7.4


Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy