How to Install PHP 7.4 on Ubuntu 24.04

Updated on 04 April, 2025
How to Install PHP 7.4 on Ubuntu 24.04 header image

PHP 7.4 is a popular PHP release and the last mirror version for PHP 7. It is supported and required by most applications due to its extensible features and compatibility with multiple services such as database backends. You can use PHP 7.4 with all supported extensions on Ubuntu 24.04 and integrate applications such as web servers to deliver dynamic web applications.

This article explains how to install PHP 7.4 on Ubuntu 24.04. You will use PHP, PHP 7.4 FPM, and common extensions to deliver dynamic web applications while integrating supported services such as web servers with PHP.

Prerequietes

Before you begin, you need to:

Add the PHP PPA to the APT Package Manager

PHP 7.4 is discontinued and not available in the APT package sources on Ubuntu 24.04. Adding a Personal Package Archive (PPA) repository source allows you to install PHP 7.4 with all supported PECL (PHP Extension Community Library) extensions required in most applications. Follow the steps below to add the ondrej/ppa source to the APT package sources on Ubuntu 24.04.

  1. Update the APT package information index.

    console
    $ sudo apt update
    
  2. Add the ondrej/ppa source to your APT sources.

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

    Press Enter when prompted to add the PPA to your APT sources.

    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.
  3. Update the APT package index to apply the PPA repository information.

    console
    $ sudo apt update
    

Install PHP 7.4

You can install PHP 7.4 on Ubuntu 24.04 after adding the main PPA source on your server. Follow the steps below to install PHP 7.4 and all required extensions on Ubuntu 24.04.

  1. Update the APT package index.

    console
    $ sudo apt update
    
  2. Install PHP 7.4

    console
    $ sudo apt install php7.4 -y
    
  3. Check the installed PHP version and verify that it's 7.4.

    console
    $ php -v
    

    Use the php7.4 -v command if you have another installed PHP version on your server.

    Output:

    PHP 7.4.33 (cli) (built: Dec 24 2024 07:12:16) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
        with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
  4. Install common PHP 7.4 extensions.

    console
    $ sudo apt install php7.4-mysql php7.4-gd php7.4-xml php7.4-zip php7.4-mbstring php7.4-curl php7.4-json -y
    

    The command installs the following common PHP extensions on the server.

    • php-mysql: Connects PHP to MySQL database sources.
    • php-gd: Used for image manipulation.
    • php-xml: Enables XML file support in PHP applications.
    • php-zip: Enables ZIP compression support in PHP applications.
    • php-mbstring: Handles multistring data in PHP applications.
    • php-curl: Allows PHP applications to create connections to external APIs
    • php-json: Enables JSON encoding and decoding in PHP applications.

Install PHP 7.4 FPM

PHP-FPM (FastCGI Process Manager) is a high-performance process manager for PHP that efficiently handles connections between PHP and other applications or services. PHP-FPM enables efficient and scalable connections between PHP and other applications using a UNIX socket or port. It's available as a separate module and is not installed with PHP directly. Follow the steps below to install PHP 7.4 FPM on Ubuntu 24.04 to optimize and handle PHP connections.

  1. Update the APT package information index.

    console
    $ sudo apt update
    
  2. Install PHP 7.4 FPM.

    console
    $ sudo apt install php7.4-fpm -y
    
  3. Enable the PHP 7.4 FPM service to start at boot.

    console
    $ sudo systemctl enable php7.4-fpm
    
  4. Start the PHP 7.4 FPM service.

    console
    $ sudo systemctl start php7.4-fpm
    
  5. Check the PHP 7.4 FPM status and verify that it's active and running.

    console
    $ sudo systemctl status php7.4-fpm
    

    Output:

    ● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
        Loaded: loaded (/usr/lib/systemd/system/php7.4-fpm.service; enabled; preset: enabled)
        Active: active (running) since Wed 2025-03-19 00:30:07 UTC; 1min 41s ago
        Docs: man:php-fpm7.4(8)
    Main PID: 27348 (php-fpm7.4)
        Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
        Tasks: 3 (limit: 2265)
        Memory: 8.3M (peak: 9.1M)
            CPU: 82ms
        CGroup: /system.slice/php7.4-fpm.service
                ├─27348 "php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)"
                ├─27350 "php-fpm: pool www"
                └─27351 "php-fpm: pool www"

Configure PHP 7.4

PHP 7.4 FPM uses pools to configure the PHP process information, enable and optimize PHP connections with other applications. Follow the steps below to configure PHP 7.4 pools and test the connection to PHP on Ubuntu 24.04.

  1. List the files in the /etc/php/7.4/fpm/ directory and verify that the php-fpm.conf file is available.

    console
    $ ls /etc/php/7.4/fpm
    

    Output:

    conf.d  php-fpm.conf  php.ini  pool.d

    The /etc/php/7.4/fpm directory is the main configuration directory for PHP 7.4 FPM that includes the pool and configuration information. The php-fpm.conf file includes the main configuration information and links to the pool.d directory which includes pool configurations.

  2. Open the www.conf default configuration using a text editor such as vim.

    console
    $ sudo vim /etc/php/7.4/fpm/pool.d/www.conf
    
  3. Verify the [www] pool configuration name.

    ini
    [www]
    
  4. Verify the user and group configuration the pool runs as.

    ini
    user = www-data
    group = www-data
    

    PHP-FPM uses the www-data user and group to run on the server by default. Specifying a different user allows PHP-FPM to run and interact with other applications.

  5. Locate and verify the default listen configuration.

    ini
    listen = /run/php/php7.4-fpm.sock
    

    The default configuration specifies the UNIX socket used to handle PHP connections on the server. Specifying an IP address like 127.0.0.1:9000 enables PHP FPM to listen for connections using a TCP port and address.

  6. Find additional configurations, including pm to modify how PHP FPM handles connections on the server.

    ini
    pm = dynamic
    pm.max_children = 5
    pm.start_servers = 2
    pm.min_spare_servers = 1
    pm.max_spare_servers = 3
    

    Save the www.conf file and close the text editor to save the pool configuration changes.

  7. Create new configurations in the pool.d directory to set up additional custom pool configurations with the .conf extension to handle PHP connections on the server.

    console
    $ sudo vim /etc/php/7.4/fpm/pool.d/<poolname>.conf
    
  8. Restart PHP 7.4 FPM to apply the pool configuration changes.

    console
    $ sudo systemctl restart php7.4-fpm
    

Test PHP 7.4

Follow the steps below to create a sample PHP application and test PHP 7.4 on your Ubuntu 24.04 server.

  1. Test the active PHP version and verify that it's 7.4.

    console
    $ php -v
    

    Or, run php7.4 -v if multiple versions are installed.

    console
    $ php7.4 -v
    

    Output:

    PHP 7.4.33 (cli) (built: Dec 24 2024 07:12:16) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
        with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
  2. Create an app.php test application file.

    console
    $ vim app.php
    
  3. Enter the following PHP code into the file.

    php
    <?php
    
    echo "Greetings from Vultr"
    ?>
    

    Save the app.php file and close the text editor.

    The PHP code in the above file displays a Greetings from Vultr message when it runs.

  4. Run the app.php application using PHP.

    console
    $ php app.php
    

    Verify that the PHP application runs without any errors in your output.

    Greetings from Vultr

Conclusion

You have installed PHP 7.4 on Ubuntu 24.04 and configured it to run using PHP FPM pools. You can use PHP 7.4 with most dynamic applications and install additional modules enables you to integrate PHP with other services, including Nginx, and MySQL, to process requests depending on your project needs.

Comments

No comments yet.