---
title: How to Install PHP 8 on Ubuntu 24.04
url: https://docs.vultr.com/how-to-install-php-8-on-ubuntu-24-04
description: Learn how to install PHP 8 on Ubuntu 24.04 with step-by-step instructions. Includes configuration tips and troubleshooting for a smooth setup process.
publish_date: 2025-05-08T13:27:17.989793Z
last_updated: 2025-05-08T13:27:17.989793Z
author: Oluwadamilola Oshungboye
header_image: https://assets.vultrdevrel.com/docs-main-doc-assets-1/2212/10673418-d4ce-42b4-ba19-c9a8fd37c176.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

PHP (Hypertext Preprocessor) is a widely used, open-source scripting language for building dynamic and interactive web applications. To take advantage of its latest capabilities, install PHP 8 on Ubuntu 24.04, which includes PHP 8.4’s performance enhancements such as JIT compilation, improved type safety, and expanded syntax features.

This article shows you how to install PHP 8.4 on Ubuntu 24.04 using the `ppa:ondrej/php` repository. You'll configure PHP-FPM, verify the installation using two test methods (Apache and PHP's built-in server), and ensure common extensions are working properly.

## Prerequisites

Before you begin:

* Have an [Ubuntu 24.04 server](https://www.vultr.com/servers/ubuntu).
* [Access the server via SSH](https://docs.vultr.com/how-to-use-ssh-with-vultr-servers) as a non-root user with `sudo` privileges.
* [Update the server](https://docs.vultr.com/how-to-update-a-vultr-cloud-server#how-to-update-debian--ubuntu).

## Add the PHP PPA Repository

Ubuntu’s default package sources may not include older PHP 8.x versions. To install PHP 8.4, you’ll use the widely trusted `ppa:ondrej/php` Personal Package Archive (PPA), which offers maintained versions and related extensions.

1. Update the APT package index.

    ```console
    $ sudo apt update
    ```

1. Add the `ppa:ondrej/php` repository to your APT sources.

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

    Press :key_enter: when prompted to add the PPA to your APT sources.

1. Update the APT package index to apply the PPA repository information.

    ```console
    $ sudo apt update
    ```

1. PHP 8.4 is currently available through the `ppa:ondrej/php` repository. You can verify the available version in your APT sources by running:

    ```console
    $ sudo apt policy php
    ```

    Output.

    ```
    php:
      Installed: (none)
      Candidate: 2:8.4+99+ubuntu24.04.1+deb.sury.org
      Version table:
         2:8.4+99+ubuntu24.04.1+deb.sury.org 500
            500 http://ppa.launchpad.net/ondrej/php/ubuntu noble/main amd64 Packages
         2:8.2+93ubuntu1 500
            500 http://archive.ubuntu.com/ubuntu noble/main amd64 Packages
    ```

    This confirms that PHP 8.4 is available from the `ppa:ondrej/php` repository.

    For the latest official release details, refer to the [PHP Releases page](https://www.php.net/releases/).

## Install PHP 8 on Ubuntu 24.04

Now that you've added the PPA, install PHP 8.4 and the essential extensions required by most modern web applications.

1. Install PHP 8.4.

    ```console
    $ sudo apt install php8.4 -y
    ```

1. Install commonly used PHP extensions.

    ```console
    $ sudo apt install php8.4-common php8.4-cli php8.4-opcache php8.4-mysql php8.4-xml php8.4-curl php8.4-zip php8.4-mbstring php8.4-gd php8.4-intl php8.4-bcmath -y
    ```

    These extensions are frequently used in content management systems, frameworks, and APIs:

    * `php8.4-common`: Core PHP files  
    * `php8.4-cli`: Command-line interface  
    * `php8.4-opcache`: Bytecode caching for performance  
    * `php8.4-mysql`: MySQL/MariaDB database support  
    * `php8.4-xml`: XML parsing  
    * `php8.4-curl`: cURL library support  
    * `php8.4-zip`: ZIP archive handling  
    * `php8.4-mbstring`: Multibyte string encoding (UTF-8, etc.)  
    * `php8.4-gd`: Image manipulation  
    * `php8.4-intl`: Internationalization support  
    * `php8.4-bcmath`: Arbitrary precision math

1. Verify the PHP installation.

    ```console
    $ php -v
    ```

    Output.

    ```
    PHP 8.4.6 (cli) (built: Apr 11 2025 02:19:40) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.4.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.6, Copyright (c), by Zend Technologies
    ```

1. List installed PHP versions and optionally make PHP 8.4 the default.

    ```console
    $ ls /etc/php
    ```

    If only PHP 8.4 is installed, set it as the default system version:

    ```console
    $ sudo update-alternatives --install /usr/bin/php php /usr/bin/php8.4 84
    ```

    Then confirm:

    ```console
    $ php -v
    ```

1. Verify active modules to ensure extensions are loaded:

    ```console
    $ php -m
    ```

    This lists all active PHP modules.

## Install PHP 8 FPM

PHP-FPM (FastCGI Process Manager) runs PHP as a separate background service and handles dynamic requests more efficiently than traditional CGI. It improves performance, resource control, and is ideal for high-traffic applications. Follow the steps below to [set up PHP-FPM](https://docs.vultr.com/how-to-install-php-and-php-fpm-on-ubuntu-24-04) for optimal performance and efficiency.

1. Install PHP 8.4 FPM.

    ```console
    $ sudo apt install php8.4-fpm -y
    ```

1. Start the PHP-FPM service.

    ```console
    $ sudo systemctl start php8.4-fpm
    ```

1. Enable PHP-FPM to start automatically on boot.

    ```console
    $ sudo systemctl enable php8.4-fpm
    ```

1. Check the status of PHP-FPM service.

    ```console
    $ sudo systemctl status php8.4-fpm
    ```

    Output.

    ```
    ● php8.4-fpm.service - The PHP 8.4 FastCGI Process Manager
    Loaded: loaded (/lib/systemd/system/php8.4-fpm.service; enabled; vendor preset: enabled)
    Active: active (running) since Wed 2025-04-11 02:19:40 UTC; 1min 30s ago
    Main PID: 12345 (php-fpm8.4)
    Status: "Processes active: 0, idle: 1, Requests: 1, slow: 0, Traffic: 0req/sec"
    ```

    Press :key_q: to exit the status output.

## Configure PHP-FPM Socket (For Apache Integration)

When using PHP-FPM with Apache, it's recommended to connect via a secure Unix socket instead of TCP for better performance and security. This section shows how to configure PHP-FPM to use a socket that Apache can access.

1. Open the PHP-FPM pool configuration file.

    ```console
    $ sudo nano /etc/php/8.4/fpm/pool.d/www.conf
    ```

1. Update the following lines (if not already present).

    ```ini
    listen = /run/php/php8.4-fpm.sock
    listen.owner = www-data
    listen.group = www-data
    listen.mode = 0660
    ```

    These settings allow Apache (running as `www-data`) to send PHP requests through the socket used by PHP-FPM.

PHP-FPM allows Apache to delegate PHP processing to a separate process manager, improving performance and resource handling under heavy traffic. The integration is seamless with modules like `proxy_fcgi` and configuration snippets enabled through `a2enconf`.

For advanced tuning options (e.g., process limits, slow logs), see the [official PHP-FPM documentation](https://www.php.net/manual/en/install.fpm.configuration.php).

??? note "Test PHP Using the Built-In Web Server (Optional)"

    PHP includes a built-in development server for lightweight testing. This method is ideal for validating that PHP is working correctly before setting up Apache or Nginx.

    1. Create a test directory and PHP file:

        ```console
        $ mkdir ~/phptest && cd ~/phptest
        ```

        ```console
        $ echo "<?php echo 'Greetings from Vultr'; ?>" > index.php
        ```

    1. Start the PHP development server:

        ```console
        $ php8.4 -S 0.0.0.0:8000
        ```

    1. Open `http://SERVER-IP:8000` in your browser.

        You should see:

        ```
        Greetings from Vultr
        ```

    This method is useful for basic testing but not suitable for production environments.

## Test and Use PHP 8

This section guides you through integrating Apache with PHP-FPM and verifying the setup with a sample PHP script. Using `proxy_fcgi`, Apache delegates PHP processing to PHP-FPM, improving performance and scalability.

If Apache is not already installed, install it:

```console
$ sudo apt install apache2
```

1. Verify the Apache service is running.

    ```console
    $ sudo systemctl status apache2
    ```

    Output.

    ```
    ● apache2.service - The Apache HTTP Server
    Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
    Active: active (running) since Sun 2025-04-13 02:19:40 UTC; 8h ago
    ...
    ```

    Press :key_q: to exit the status output.

1. Enable required Apache modules for PHP-FPM:

    ```console
    $ sudo a2enmod proxy_fcgi setenvif
    ```

1. Enable the PHP-FPM configuration for Apache:

    ```console
    $ sudo a2enconf php8.4-fpm
    ```

1. Restart Apache to apply changes:

    ```console
    $ sudo systemctl restart apache2
    ```

1. Allow HTTP traffic through the firewall.

    ```console
    $ sudo ufw allow 80
    ```

1. Reload the firewall configuration.

    ```console
    $ sudo ufw reload
    ```

1. Create a test `info.php` file in the Apache web root directory.

    ```console
    $ sudo nano /var/www/html/info.php
    ```

1. Add the following code to the file.

    ```php
    <?php
    phpinfo();
    ?>
    ```

    Save and exit the editor.

1. Access your server's IP address in a web browser and load the `/info.php` URL path to view the PHP information page. Replace `SERVER-IP` with your server's actual IP address.

    ```
    http://SERVER-IP/info.php
    ```

    > [!WARNING]
    > After verifying PHP info, delete info.php to avoid exposing server configuration.

    ```console
    $ sudo rm /var/www/html/info.php
    ```

## Conclusion

In this article, you installed PHP 8.4 on Ubuntu 24.04, added the required PPA repository, installed core PHP extensions, and configured PHP-FPM. You also verified the installation by creating a test script served through Apache. With PHP 8.4 now running on your system, you’re ready to start building and deploying modern web applications using the latest features and improvements. For more information, visit the [official PHP documentation](https://www.php.net/docs.php).
