How to Install PHP and PHP-FPM on Ubuntu 26.04

Updated on 24 April, 2026
Install and configure the PHP scripting language and PHP-FPM process manager on an Ubuntu 26.04 for efficient FastCGI-based request handling.
How to Install PHP and PHP-FPM on Ubuntu 26.04 header image

PHP (Hypertext Preprocessor) is a widely used server-side scripting language designed for building dynamic web applications. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation that manages worker processes efficiently, offering features such as adaptive process spawning, graceful restarts, and improved resource handling compared to traditional CGI methods.

This article explains how to install PHP and PHP-FPM on an Ubuntu 26.04 server. It covers installing common PHP extensions, configuring the PHP-FPM pool settings, testing PHP with Nginx, and running multiple PHP versions side by side.

Prerequisites

Before you begin, you need to:

Install PHP

The default Ubuntu 26.04 APT repositories include the latest PHP package. The following steps update the package index and install the PHP command-line interpreter.

  1. Update the APT package index.

    console
    $ sudo apt update
    
  2. Install PHP.

    console
    $ sudo apt install php -y
    
  3. Confirm the installed PHP version.

    console
    $ php -v
    

    Your output should be similar to the one below:

    PHP 8.5.2 (cli) (built: Jan 21 2026 17:35:28) (NTS)
    Copyright (c) The PHP Group
    Built by Ubuntu
    Zend Engine v4.5.2, Copyright (c) Zend Technologies
        with Zend OPcache v8.5.2, Copyright (c), by Zend Technologies

Install PHP Extensions

PHP extensions add capabilities such as database connectivity, image processing, and encryption support that most web applications and frameworks require. The following steps install commonly used extensions and verify the active modules.

  1. Install common PHP extensions.

    console
    $ sudo apt install -y php-mysql php-mbstring php-bcmath php-zip php-gd php-curl php-xml
    

    The command installs the following extensions:

    • php-mysql: Provides connectivity to MySQL and MariaDB databases.
    • php-mbstring: Adds support for multibyte string encoding such as UTF-8.
    • php-bcmath: Enables arbitrary-precision arithmetic operations.
    • php-zip: Adds support for reading and writing ZIP archives.
    • php-gd: Provides image creation and manipulation functions.
    • php-curl: Enables HTTP requests and URL transfers from PHP.
    • php-xml: Adds XML parsing and generation support.

    Run the following command to list all available PHP extensions for your installed version.

    console
    $ sudo apt-cache search php | grep "^php8.5"
    
  2. View all active PHP modules.

    console
    $ php -m
    

    Your output should be similar to the one below:

    [PHP Modules]
    bcmath
    calendar
    Core
    ctype
    curl
    date
    dom
    exif
    FFI
    ......
    
    [Zend Modules]
    Zend OPcache

Install and Configure PHP-FPM

PHP-FPM is available in the default APT repositories and matches the installed PHP version. The following steps install PHP-FPM, verify the installation, and configure the worker pool settings.

  1. Install PHP-FPM.

    console
    $ sudo apt install php-fpm -y
    
  2. Confirm the installed PHP-FPM version.

    console
    $ php-fpm8.5 -v
    

    Your output should be similar to the one below:

    PHP 8.5.2 (fpm-fcgi) (built: Jan 21 2026 17:35:28) (NTS)
    Copyright (c) The PHP Group
    Built by Ubuntu
    Zend Engine v4.5.2, Copyright (c) Zend Technologies
        with Zend OPcache v8.5.2, Copyright (c), by Zend Technologies
  3. List the PHP configuration directories to verify that the fpm directory exists.

    console
    $ ls /etc/php/8.5/
    

    Your output should be similar to the one below:

    apache2  cli  fpm  mods-available
  4. Open the default PHP-FPM pool configuration file using a text editor such as Nano.

    console
    $ sudo nano /etc/php/8.5/fpm/pool.d/www.conf
    
    • Find the [www] directive to verify the pool name.

      ini
      [www]
      
    • Find the user and group directives to confirm that PHP-FPM runs as the www-data user. Web servers such as Nginx require this user for proper file access.

      ini
      user = www-data
      group = www-data
      
    • Find the listen directive to verify the Unix socket path used to connect to the PHP-FPM service.

      ini
      listen = /run/php/php8.5-fpm.sock
      
    • Adjust the following process manager directives based on your server resources and expected traffic.

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

      Within the configuration:

      • pm: Sets the process manager mode. Options include static (fixed number of workers), dynamic (scales workers based on demand), and ondemand (spawns workers only when requests arrive).
      • pm.max_children: Defines the maximum number of child processes that can run simultaneously.
      • pm.start_servers: Sets how many child processes to create at startup.
      • pm.min_spare_servers: Maintains a minimum number of idle worker processes.
      • pm.max_spare_servers: Limits the maximum number of idle worker processes.

      Save and close the file.

  5. Restart PHP-FPM to apply the configuration changes.

    console
    $ sudo systemctl restart php8.5-fpm
    

Test PHP and PHP-FPM

PHP processes scripts through the command-line interpreter, while PHP-FPM handles requests forwarded by a web server. The following steps verify both by running a PHP script from the terminal and then configuring Nginx to serve a PHP application through PHP-FPM.

  1. Create a sample PHP script.

    console
    $ nano sample.php
    
  2. Add the following content to the file.

    php
    <?php
    
    echo "Hello World! PHP is running correctly on this server.";
    
    ?>
    

    Save and close the file.

  3. Run the script using the PHP CLI.

    console
    $ php sample.php
    

    Your output should be similar to the one below:

    Hello World! PHP is running correctly on this server.
  4. Stop and disable the Apache service that is pre-installed with PHP.

    console
    $ sudo systemctl disable --now apache2
    
  5. Install the Nginx web server to test PHP-FPM integration.

    console
    $ sudo apt install nginx -y
    
  6. Back up the default Nginx virtual host configuration.

    console
    $ sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.BAK
    
  7. Create a new default Nginx configuration file.

    console
    $ sudo nano /etc/nginx/sites-available/default
    
  8. Add the following configuration to the file.

    ini
    server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        root  /var/www/html/;
        index index.html index.php index.nginx-debian.html;
    
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/run/php/php-fpm.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
        }
    }
    

    Save and close the file.

    This configuration listens on port 80 and serves files from the /var/www/html directory. Nginx forwards all .php requests to the PHP-FPM socket at /run/php/php-fpm.sock for processing through FastCGI.

  9. Test the Nginx configuration for syntax errors.

    console
    $ sudo nginx -t
    
  10. Create a PHP test file in the Nginx web root directory.

    console
    $ sudo nano /var/www/html/test.php
    
  11. Add the following content to the file.

    php
    <?php
    
    phpinfo();
    
    ?>
    

    Save and close the file.

    This script displays detailed PHP version and configuration information when accessed through a web browser.

  12. Allow HTTP traffic on port 80 through the firewall.

    console
    $ sudo ufw allow 80
    
  13. Restart Nginx to apply the configuration.

    console
    $ sudo systemctl restart nginx
    
  14. Access the PHP test page in a web browser. Replace SERVER-IP with your server's public IP address.

    http://SERVER-IP/test.php

    The browser displays the PHP information page, confirming that Nginx processes PHP requests through PHP-FPM.

Conclusion

You have installed PHP and PHP-FPM on an Ubuntu 26.04 server, configured the FPM worker pool, and verified PHP processing through Nginx. PHP-FPM integrates with web servers such as Nginx and Apache to handle dynamic application requests efficiently. For more information, refer to the official PHP documentation.

Comments