How to Install PHP 7.4 on Ubuntu?. Welcome to today’s guide on how to install PHP 7.4 on Ubuntu 20.04/18.04/16.04 Linux. The PHP release 7.4.0 has been made available for the general public and for use in Production environments.

PHP is a popular server scripting language known for creating dynamic and interactive Web pages. PHP is widely-used programming language in the Web. Use the steps below to install PHP 7.4 on Ubuntu 20.04/18.04/16.04.

Let’s consider the two installations for PHP 7.4 on Ubuntu 20.04 / Ubuntu 18.04 and Ubuntu 16.04.

Install PHP 7.4 on Ubuntu 20.04

NOTE: Ubuntu 20.04 ships with PHP 7.4 in its upstream repositories. Just install it and the extensions you with the apt package manager.

sudo apt update
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

Confirm PHP version:

$ php --version
PHP 7.4.3-4ubuntu2.19 (cli) (built: Jun 27 2023 15:49:59) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3-4ubuntu2.19, Copyright (c), by Zend Technologies

Listing all loaded PHP modules:

$ php -m

Install PHP 7.4 on Ubuntu 18.04|16.04

For the other editions of Ubuntu, use the process below:

Step 1: Add PHP PPA Repository

We’ll PPA repository which has the latest build packages of PHP. But first install dependent packages.

sudo apt update
sudo apt -y install software-properties-common

Add the repos:

sudo add-apt-repository ppa:sergey-dryabzhinsky/php74
sudo add-apt-repository ppa:sergey-dryabzhinsky/php7-modules
sudo add-apt-repository ppa:sergey-dryabzhinsky/backports
sudo add-apt-repository ppa:sergey-dryabzhinsky/packages

Step 2: Install PHP 7.4

Install PHP 7.4 on Ubuntu using the command:

sudo apt -y install php7.4

Check version installed:

$ php -v
PHP 7.4.33-SergeyD/6.1 (cli) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Use the next command to install additional packages:

sudo apt install php7.4-xxx

Example:

sudo apt install php74p-mod-{mysql,bcmath,bz2,gd,intl,mbstring,zip,json}

PHP configurations related to Apache is stored in /etc/php74/cli/php.ini

Confirm PHP version:

$ php --version
PHP 7.4.33-SergeyD/6.1 (cli) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Using PHP 7.4 with Apache

Install Apache PHP module.

sudo apt install libapache2-mod-php74

Using PHP 7.4 with Nginx

The installation of php on Ubuntu configures Apache. For users interested in running Nginx and PHP, you need to stop and disable Apache service.

sudo systemctl disable --now apache2

Then install fpm extension and nginx packages.

### Ubuntu 20.04 ###
sudo apt install nginx php7.4-fpm

### Ubuntu 18.04/16.04 ###
sudo apt install nginx php74p-fpm

PHP FPM configuration file is /etc/php74/fpm/pool.d/www.conf. Enjoy using PHP 7.4 on Ubuntu 20.04/ Ubuntu 18.04 / Ubuntu 16.04 Linux system.

Conclusion

In conclusion, this source supplied a complete information on how to installation PHP 7.4 on Ubuntu 20.04, 18.04, and 16.04. PHP 7.4 is a widely-used programming language for growing dynamic and interactive web pages. For Ubuntu 20.04, PHP 7.4 is easily reachable in the upstream repositories, making it convenient to set up the use of the apt package deal manager. However, for Ubuntu 18.04 and 16.04, extra steps are required.

The article outlined the process of adding the PHP PPA repository and installing PHP 7.4 using the appropriate commands. It also mentioned how to configure PHP with Nginx for those interested in using Nginx instead of Apache. By following the instructions provided, users can enjoy the benefits of PHP 7.4 on their Ubuntu systems. Whether you are a novice or an skilled developer, having PHP conveniently reachable on your Ubuntu machine empowers you to construct strong and dynamic net functions efficiently.

For other systems:

How To Install PHP 7.4 on Fedora

How To Install PHP 7.4 on CentOS 8 / RHEL 8

How To Install PHP 7.4 on CentOS 7

How To Install PHP 7.4 on Debian

YOU CAN SUPPORT OUR WORK WITH A CUP OF COFFEE


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

17 COMMENTS

  1. Due to Ubuntu 16.04 (Xenial) has reached End of Standard Support, the php package also been removed from Ondrej repository. This installation method is not works anymore on Xenial.

    Any alternative?

  2. This is incorrect for 16/18 as they are out of support and have been removed from the https://ppa.launchpadcontent.net/ondrej/php/ubuntu repos.

    Had to use this instead.
    sudo add-apt-repository ppa:sergey-dryabzhinsky/php74
    sudo add-apt-repository ppa:sergey-dryabzhinsky/php7-modules
    sudo add-apt-repository ppa:sergey-dryabzhinsky/backports
    sudo add-apt-repository ppa:sergey-dryabzhinsky/packages

  3. Hi

    I am unable to install FPM can you help with it?

    sudo apt install php74p-fpm

    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    php74p-fpm is already the newest version (7.4.33-0sergeyd6.1~18.04.1).
    0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
    2 not fully installed or removed.
    After this operation, 0 B of additional disk space will be used.
    Do you want to continue? [Y/n] y
    Setting up php74-fpm (7.4.33-0sergeyd6.1~18.04.1) …
    update-rc.d: error: unable to read /etc/init.d/php74-fpm
    dpkg: error processing package php74-fpm (–configure):
    installed php74-fpm package post-installation script subprocess returned error exit status 1
    dpkg: dependency problems prevent configuration of php74p-fpm:
    php74p-fpm depends on php74-fpm; however:
    Package php74-fpm is not configured yet.

    dpkg: error processing package php74p-fpm (–configure):
    dependency problems – leaving unconfigured
    No apport report written because the error message indicates its a followup error from a previous failure.
    Errors were encountered while processing:
    php74-fpm
    php74p-fpm
    E: Sub-process /usr/bin/dpkg returned an error code (1)

    • Hello @Jay Sheth
      The above error is beacuse you already have PHP-FPM installed. You can verify with the command:
      php-fpm7.4 -v

      If present, proceed and use it as desired.

      • Hi,

        unable to install php74p-fpm. I’m facing the same issue. I checked “php-fpm7.4 -v” but I returned Command “‘php-fpm7.4’ not found, did you mean”.
        When I use the command “sudo apt install php74p-fpm” I get this:

        Reading package lists… Done
        Building dependency tree
        Reading state information… Done
        Note, selecting ‘php74p-fpm’ instead of ‘php7.4-fpm’
        php74p-fpm is already the newest version (7.4.33-0sergeyd6.1~18.04.1).
        0 upgraded, 0 newly installed, 0 to remove and 65 not upgraded.
        2 not fully installed or removed.
        After this operation, 0 B of additional disk space will be used.
        Do you want to continue? [Y/n] y
        Setting up php74-fpm (7.4.33-0sergeyd6.1~18.04.1) …
        update-rc.d: error: unable to read /etc/init.d/php74-fpm
        dpkg: error processing package php74-fpm (–configure):
        installed php74-fpm package post-installation script subprocess returned error exit status 1
        dpkg: dependency problems prevent configuration of php74p-fpm:
        php74p-fpm depends on php74-fpm; however:
        Package php74-fpm is not configured yet.

        dpkg: error processing package php74p-fpm (–configure):
        dependency problems – leaving unconfigured
        No apport report written because the error message indicates its a followup error from a previous failure.
        Errors were encountered while processing:
        php74-fpm
        php74p-fpm
        E: Sub-process /usr/bin/dpkg returned an error code (1)

      • output from php74-fpm -v
        PHP 7.4.33-SergeyD/6.1 (fpm-fcgi)
        Copyright (c) The PHP Group
        Zend Engine v3.4.0, Copyright (c) Zend Technologies

        i also had the same issue

        • This shows that you already have PHP-FPM installed, you can just proceed and use it as desired. No need to do another installation.

          • Hi,

            I get this message when I use “php-fpm7.4 -v”

            Command ‘php-fpm7.4’ not found, did you mean:
            command ‘php-fpm7.2’ from deb php7.2-fpm
            Try: sudo apt install

            Please let me know how to resolve and install fpm in PHP 7.4 version

          • Hi,

            I’m facing same issue when i use “sudo apt install php74p-fpm” I get error

            Reading package lists… Done
            Building dependency tree
            Reading state information… Done
            php74p-fpm is already the newest version (7.4.33-0sergeyd6.1~18.04.1).
            0 upgraded, 0 newly installed, 0 to remove and 66 not upgraded.
            2 not fully installed or removed.
            After this operation, 0 B of additional disk space will be used.
            Do you want to continue? [Y/n] y
            Setting up php74-fpm (7.4.33-0sergeyd6.1~18.04.1) …
            update-rc.d: error: unable to read /etc/init.d/php74-fpm
            dpkg: error processing package php74-fpm (–configure):
            installed php74-fpm package post-installation script subprocess returned error exit status 1
            dpkg: dependency problems prevent configuration of php74p-fpm:
            php74p-fpm depends on php74-fpm; however:
            Package php74-fpm is not configured yet.

            dpkg: error processing package php74p-fpm (–configure):
            dependency problems – leaving unconfigured
            No apport report written because the error message indicates its a followup error from a previous failure.
            Errors were encountered while processing:
            php74-fpm
            php74p-fpm
            E: Sub-process /usr/bin/dpkg returned an error code (1)

            Also, I checked “php74-fpm -v” it’s shows PHP version but I need to config nginx I can’t find “fpm.sock” file old version path is “/var/run/php/php7.2-fpm.sock” I need to update the PHP7.4 fpm sock file but I can’t find it.
            Please let me know how to resolve it

LEAVE A REPLY

Please enter your comment!
Please enter your name here