How to Install PHP 7.4 FPM on Ubuntu 18.04

Share:
how-to-install-php-7-4-fpm-on-ubuntu-18-04

Other than developing web applications, I'm also acting as system administrator. Most of my clients are not very familiar with Linux environment.

Some of the servers I maintained are still running Ubuntu 18.04. Although it's still being actively maintained, the latest official PHP version from Ubuntu is 7.2.24. Some of our Laravel applications are newer, hence it require PHP >= 7.4. There's no other way than upgrade our PHP version.

PHP 7.2.24-0ubuntu0.18.04.10 (cli) (built: Oct 25 2021 17:47:59) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24-0ubuntu0.18.04.10, Copyright (c) 1999-2018, by Zend Technologies
Ubuntu 14.04, 16.04, 18.04 EOL

To upgrade our PHP version to 7.4, we must add a PPA repository maintained by Ondřej Surý called ondrej/php. First, let's update our system's apt repository first.

Update apt Repository

First, we need to make sure that our system is up-to-date. On your terminal, run this command:

$ sudo apt update
$ sudo apt upgrade

Add Repository

Before we add a new repository, we need to install necessary package:

$ sudo apt -y install software-properties-common

To add ondrej/php repository, run this command:

$ sudo add-apt-repository ppa:ondrej/php

It will respond with message like below:

 Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/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: https://deb.sury.org/#debian-dpa

You can get more information about the packages at https://deb.sury.org

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

BUGS&FEATURES: This PPA now has a issue tracker:
https://deb.sury.org/#bug-reporting

CAVEATS:
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: https://donate.sury.org/

WARNING: add-apt-repository is broken with non-UTF-8 locales, see
https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

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

Just press ENTER to continue with repository addition.

The last step is to install PHP 7.4 on Ubuntu 18.04 Bionic. Before installation, update system package list on added repositories.

PHP 7.4 Installation

Let's update our system's repository again.

$ sudo apt update

Then we can continue to install PHP 7.4 FPM on Ubuntu 18.04:

$ 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

Verification

To verify that our installation went correctly, enter this command:

$ php -v

It must respond with something like this:

PHP 7.4.25 (cli) (built: Oct 22 2021 12:33:59) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.25, Copyright (c), by Zend Technologies

Final Words

I hope that you now know how to install PHP 7.4 on Ubuntu 18.04 Bionic. If you run into any issues or have any feedback feel free to drop a comment below.

Tags PHP Linux
Share:

1 comment

  1. This is the message I get after following all directions, please advise.

    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
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: Unable to locate package php7.4-fpm
    E: Couldn't find any package by glob 'php7.4-fpm'
    E: Couldn't find any package by regex 'php7.4-fpm'
    E: Unable to locate package php7.4-bcmath
    E: Couldn't find any package by glob 'php7.4-bcmath'
    E: Couldn't find any package by regex 'php7.4-bcmath'
    E: Unable to locate package php7.4-curl
    E: Couldn't find any package by glob 'php7.4-curl'
    E: Couldn't find any package by regex 'php7.4-curl'
    E: Unable to locate package php7.4-gd
    E: Couldn't find any package by glob 'php7.4-gd'
    E: Couldn't find any package by regex 'php7.4-gd'
    E: Unable to locate package php7.4-mbstring
    E: Couldn't find any package by glob 'php7.4-mbstring'
    E: Couldn't find any package by regex 'php7.4-mbstring'
    E: Unable to locate package php7.4-mysql
    E: Couldn't find any package by glob 'php7.4-mysql'
    E: Couldn't find any package by regex 'php7.4-mysql'
    E: Unable to locate package php7.4-xml
    E: Couldn't find any package by glob 'php7.4-xml'
    E: Couldn't find any package by regex 'php7.4-xml'
    E: Unable to locate package php7.4-zip
    E: Couldn't find any package by glob 'php7.4-zip'
    E: Couldn't find any package by regex 'php7.4-zip'

Leave a reply

Your email address will not be published. Required fields are marked *