---
title: How to Install PHP 8 on Debian 12
url: https://docs.vultr.com/how-to-install-php-8-on-debian-12
description: Learn how to install PHP 8 on Debian 12 with step-by-step instructions. This guide covers multiple installation methods and configuration options for your server.
publish_date: 2025-06-12T14:29:14.035448Z
last_updated: 2025-06-12T14:29:14.035448Z
author: Hitesh Jethva
header_image: https://assets.vultrdevrel.com/docs-main-doc-assets-1/2237/2970a128-2a55-48e9-88b0-2942e5c3d0d9.png
---

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

PHP (Hypertext Preprocessor) is a widely used, open-source server-side scripting language for building dynamic websites and applications. The PHP 8.x series introduces significant performance improvements, including Just-In-Time (JIT) compilation, named arguments, union types, and other modern features that enhance efficiency and modernize the development experience.

This article guides you through installing PHP 8.4 on Debian 12, setting up PHP-FPM for efficient request handling, and integrating it with the Apache web server.

## Prerequisites

Before you begin, you need to:

* Have access to a [Debian 12 instance](https://www.vultr.com/servers/debian) as a non-root sudo user.

## Add the PHP PPA Repository

Debian 12's default APT repositories may not include the latest PHP releases. The SURY repository, maintained by Debian PHP package maintainer Ondřej Surý, provides up-to-date PHP versions and is widely trusted in the community.

1. Update the system package index and upgrade existing packages.

    ```console
    $ sudo apt update && sudo apt upgrade -y
    ```

1. Install required dependencies.

    ```console
    $ sudo apt install -y lsb-release apt-transport-https ca-certificates
    ```

1. Import the SURY GPG key to verify the repository's package authenticity.

    ```console
    $ sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
    ```

1. Add the SURY PHP repository to your system's APT sources.

    ```console
    $ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
    ```

1. Update the APT package index again to include the new repository.

    ```console
    $ sudo apt update -y
    ```

1. PHP 8.4 is currently available through the `packages.sury.org/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+96+0~20250402.56+debian12~1.gbp84a5b7
      Version table:
         2:8.4+96+0~20250402.56+debian12~1.gbp84a5b7 500
            500 https://packages.sury.org/php bookworm/main amd64 Packages
         2:8.2+93 500
            500 https://deb.debian.org/debian bookworm/main amd64 Packages
            500 https://debian.mirror.constant.com bookworm/main amd64 Packages

    ```

    This confirms that PHP 8.4 is available from the SURY repository.

    You can also visit the [PHP Releases page](https://www.php.net/releases/) to verify the latest official version.

## Install PHP 8

With the SURY repository enabled, you can now install PHP 8.4 and configure commonly used extensions. These are required for features like database access, string manipulation, file handling, and API communication.

1. Install PHP 8.4.

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

1. Verify the installed version.

    ```console
    $ php8.4 -v
    ```

    Output:

    ```
    PHP 8.4.6 (cli) (built: Apr 11 2025 02:09:29) (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 set PHP 8.4 as the default system version.

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

    If only PHP 8.4 is installed, you can set it as the default system-wide PHP interpreter using `update-alternatives`.

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

    Then verify:

    ```console
    $ php -v
    ```

1. Install common PHP extensions used for database, networking, and string handling.

    ```console
    $ sudo apt install -y php8.4-mysql php8.4-curl php8.4-xml php8.4-mbstring
    ```

   * `php8.4-mysql`: MySQL/MariaDB database support
   * `php8.4-curl`: Enables cURL for remote data fetching
   * `php8.4-xml`: Handles XML parsing
   * `php8.4-mbstring`: Supports multibyte string encoding (important for UTF-8)

1. List the active PHP modules to verify installation.

    ```console
    $ php8.4 -m
    ```

    This lists all active PHP modules, including the extensions you just installed.

## Install PHP 8 FPM

PHP-FPM (FastCGI Process Manager) separates PHP execution from the web server, improving performance and scalability. In this section, you’ll install PHP-FPM 8.4, configure its socket permissions, and ensure it starts on boot.

1. Install PHP 8.4 FPM.

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

1. Open the default PHP-FPM pool configuration file.

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

    Define the Unix socket PHP-FPM will listen on.

    ```ini
    listen = /run/php/php8.4-fpm.sock
    ```

    Set socket permissions for Apache access.

    ```ini
    listen.owner = www-data
    listen.group = www-data
    listen.mode = 0660
    ```

    These settings ensure Apache can communicate with PHP-FPM via the socket.

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

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

1. Restart the PHP-FPM service to apply the configuration changes.

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

1. Verify PHP-FPM is running.

    ```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; preset: enabled)
         Active: active (running) since Wed 2025-04-16 07:09:39 UTC; 13s ago
           Docs: man:php-fpm8.4(8)
        Process: 13047 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/8.4/fpm/pool.d/www.conf 84 (code=exited, status=0/SUCCESS)
       Main PID: 13044 (php-fpm8.4)
    ...
    ```

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 helpful for quick testing, but it’s not recommended for production use.

## Test and Use PHP 8

PHP-FPM runs as a separate service that handles PHP execution more efficiently than traditional mod_php. It listens on a Unix socket and works alongside your web server. In this section, you’ll integrate Apache with PHP-FPM using `proxy_fcgi`, then deploy a test PHP script to confirm the setup.

1. Install Apache.

    ```console
    $ sudo apt install -y apache2
    ```

1. Enable the `proxy_fcgi` and `setenvif` modules in Apache to handle PHP via PHP-FPM.

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

1. Enable the PHP-FPM configuration for Apache.

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

1. Restart the Apache service to apply the changes.

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

1. Create a sample PHP application file.

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

    Add the following content to the file:

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

1. Allow HTTP traffic through the firewall.

    ```console
    $ sudo ufw allow 80/tcp
    ```

1. Reload the firewall configuration.

    ```console
    $ sudo ufw reload
    ```

1. Open a browser and visit:

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

    Replace `SERVER-IP` with your server’s actual IP address. You should see the PHP information page confirming the active PHP version and configuration.

    ![Verify PHP Installation](https://assets.vultrdevrel.com/docs-main-doc-assets-1/2237/47bb94fd-4513-4f9f-8ad7-45c897be3029.png)

## Conclusion

In this article, you installed PHP 8.4 and PHP-FPM on a Debian 12 server. You added the SURY repository to access the latest PHP packages, installed and verified PHP 8.4, configured PHP-FPM for efficient process management, and integrated it with the Apache web server. You also deployed a test PHP script to confirm the setup works as expected. With this environment in place, your server is now ready for hosting modern PHP applications. For more details on PHP features and configuration, refer to the [official PHP documentation](https://www.php.net/docs.php).
