Skip to content

How to Install PHP on Ubuntu 26.04 (PHP 8.6 & 8.5)

Install PHP on Ubuntu 26.04 LTS: Ubuntu's own PHP 8.5, or PHP 8.6, 8.4 and older from the Sury repository. Add extensions, set up Apache or Nginx, switch versions.

Steps
8
Category
PHP
Covers
Ubuntu
Versions & support
About PHP →, About Ubuntu →
On this page 8 steps

PHP still runs a large share of the web. WordPress, Laravel, Drupal, Nextcloud and countless in-house applications depend on it, so installing PHP is usually one of the first jobs on a new Ubuntu 26.04 LTS (Resolute Raccoon) server.

Ubuntu 26.04 ships PHP 8.5 in its own repositories, and Canonical maintains it with security fixes for the whole life of the release. The newest release, PHP 8.6 (November 2026), and older branches such as 8.4 or 7.4 are available from the Sury PHP repository (packages.sury.org), which is maintained by Ondřej Surý. This guide covers both routes: installing Ubuntu’s PHP 8.5, or installing PHP 8.6 or another version from the Sury repository. You will also add extensions, connect PHP to Apache or Nginx, tune php.ini, run several versions side by side and test the result.

Last tested: November 2026 on Ubuntu 26.04 LTS with PHP 8.5.4 (Ubuntu) and PHP 8.6.0 (Sury repository).

Which PHP Version Can You Install on Ubuntu 26.04?

Each PHP branch gets two years of active support and then two more years of security-only fixes. This is what you can install on Ubuntu 26.04 as of November 2026:

VersionSecurity support untilOn Ubuntu 26.04
PHP 8.6Dec 31, 2030Latest release (Nov 2026). Install from the Sury repository
PHP 8.5Dec 31, 2029Ubuntu 26.04 default, installed with apt
PHP 8.4Dec 31, 2028Sury repository
PHP 8.3 and older (down to 5.6)Dec 31, 2027 or earlierSury repository. Use end-of-life branches only for legacy code

In short: use PHP 8.5 if you want packages maintained by Ubuntu itself, or PHP 8.6 if your application supports it and you want the newest features and the longest upstream support. Read about the new features in PHP 8.6, and see the PHP release tracker for current point releases.

Prerequisites

  • A system running Ubuntu 26.04 LTS (desktop or server)
  • A user account with sudo privileges
  • An internet connection

Step 1 of 8Update Your System

Refresh the package index and apply pending updates before installing anything:

sudo apt update
sudo apt upgrade -y

If the upgrade installed a new kernel, reboot the server before moving ahead.

Step 2 of 8Option A: Install PHP 8.5 from Ubuntu

PHP 8.5 is in Ubuntu’s main repositories, so you don’t need to add any extra repository. Install the interpreter and its common files:

sudo apt install php8.5 php8.5-cli php8.5-common -y

The php8.5 package needs a server API, and apt picks the Apache module by default. If you plan to use Nginx, install php8.5-fpm together with it (or install only php8.5-cli for command-line use) so Apache isn’t pulled in:

sudo apt install php8.5-cli php8.5-fpm -y

Check the installed version:

php -v

PHP 8.5.4 (cli) (built: Oct 19 2026 14:35:18) (NTS)
Copyright (c) The PHP Group
Built by Ubuntu
Zend Engine v4.5.4, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.4, Copyright (c), by Zend Technologies

The Built by Ubuntu line confirms that the package comes from Ubuntu’s repositories. Point releases and security fixes arrive with your regular sudo apt upgrade. You can now skip to Step 3.

Step 2 of 8Option B: Install PHP 8.6 or Another Version from the Sury Repository

On Ubuntu 24.04 and earlier, the usual source for other PHP versions is the ondrej/php PPA. As of November 2026, that PPA has no packages for Ubuntu 26.04: add-apt-repository ppa:ondrej/php adds it without an error, but apt finds nothing in it and sudo apt install php8.6 fails with “Unable to locate package”. The same maintainer publishes Ubuntu 26.04 builds in his own repository at packages.sury.org, and that is what this option uses. It provides every branch from 8.6 down to 5.6 for Ubuntu 26.04.

Install the tools needed to add the repository:

sudo apt install ca-certificates curl lsb-release -y

Download and install the package that contains the repository’s signing key:

curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb

Add the repository and refresh the package index. The lsb_release -sc part inserts your Ubuntu codename, which is resolute on Ubuntu 26.04:

echo "deb [signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update

Now install PHP 8.6 (CLI and PHP-FPM):

sudo apt install php8.6-cli php8.6-fpm -y

For another version, change the number in the package names. For example, PHP 8.4 or PHP 7.4:

sudo apt install php8.4-cli php8.4-fpm -y
sudo apt install php7.4-cli php7.4-fpm -y

Check the version:

php -v

PHP 8.6.0 (cli) (built: Nov 20 2026 15:07:19) (NTS)
Copyright © The PHP Group and Contributors
Built by Ubuntu
Zend Engine v4.6.0, Copyright © Zend by Perforce
    with Zend OPcache v8.6.0, Copyright ©, by Zend by Perforce

Two side effects of the Sury repository are worth knowing:

  • Its PHP 8.5 builds are newer than Ubuntu’s 8.5.4, so sudo apt upgrade replaces Ubuntu’s PHP 8.5 packages with the Sury ones.
  • The unversioned php and php-* meta-packages now point to PHP 8.6. With the repository enabled, always install versioned packages such as php8.6-curl or php8.5-curl so you get exactly the version you expect.

Warning: PHP 8.1 and older no longer receive security fixes from the PHP project. Run them only for legacy code that cannot be upgraded, and plan a migration.

Step 3 of 8Install PHP Extensions

The base package is deliberately minimal, and most applications need a handful of extensions on top of it. This set covers what WordPress, Laravel, Symfony and similar projects expect (shown for PHP 8.5; use php8.6- for PHP 8.6):

sudo apt install php8.5-{mysql,pgsql,curl,gd,mbstring,xml,zip,intl,bcmath,soap,readline} -y

List the enabled modules to verify them:

php -m

A few notes on choosing extensions:

  • php8.5-mysql and php8.5-pgsql are the database drivers. Install only the one your database uses.
  • OPcache caches compiled bytecode and is the biggest performance win on a production server. Since PHP 8.5 it is built into PHP itself, so there is no php8.5-opcache or php8.6-opcache package. Adding it to the list above makes apt stop with “Unable to locate package”. The “with Zend OPcache” line in php -v shows that it is active.
  • php8.5-mbstring, php8.5-xml and php8.5-curl are required by almost every framework and CMS.
  • Many PECL extensions are packaged too, for example php8.5-redis. The Sury repository already has redis, imagick, apcu, memcached, mongodb and xdebug for PHP 8.6. Search with apt search php8.6- rather than guessing the name.

Step 4 of 8Configure PHP with Apache

Skip this step if you use Nginx. To run PHP inside the Apache web server, install Apache and the PHP module for your version (replace 8.5 with 8.6 if you installed PHP 8.6):

sudo apt install apache2 libapache2-mod-php8.5 -y

The package enables the module automatically. Only one mod_php version can be active at a time, so if another one is enabled, disable it first (for example sudo a2dismod php8.6). Make sure the module is active and restart Apache:

sudo a2enmod php8.5
sudo systemctl restart apache2

Step 5 of 8Configure PHP with Nginx (PHP-FPM)

Nginx has no built-in PHP module, so it hands PHP requests to the FastCGI Process Manager (PHP-FPM). Install both, if you haven’t already (see our guide to Nginx on Ubuntu 26.04 for the web server setup):

sudo apt install nginx php8.5-fpm -y

Start PHP-FPM and enable it at boot:

sudo systemctl enable --now php8.5-fpm
sudo systemctl status php8.5-fpm

Then point an Nginx server block at the PHP-FPM socket. Edit your site configuration, for example /etc/nginx/sites-available/default, and add the PHP location block:


server {
    listen 80;
    server_name example.com;
    root /var/www/html;
    index index.php index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.5-fpm.sock;
    }
}

For PHP 8.6, use the php8.6-fpm service and the /run/php/php8.6-fpm.sock socket instead. Test the configuration for syntax errors, then reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

The socket path contains the PHP version number. When you later move to another PHP release, update fastcgi_pass as well. Forgetting it is the most common cause of a 502 Bad Gateway error after a PHP upgrade.

Step 6 of 8Adjust PHP Settings

Each server API has its own configuration file. The CLI reads /etc/php/8.5/cli/php.ini, Apache reads /etc/php/8.5/apache2/php.ini, and PHP-FPM reads /etc/php/8.5/fpm/php.ini (with 8.6 in the path for PHP 8.6). Editing the wrong one is a classic time waster, so check which file the CLI loads:

php --ini

Open the file for the server API your site uses:

sudo nano /etc/php/8.5/fpm/php.ini

These are sensible starting values for a typical web application:


memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120
date.timezone = UTC

Save the file and exit the editor (Ctrl + X, then Y, then Enter). Restart the service so the changes take effect:

sudo systemctl restart php8.5-fpm

For Apache with mod_php, restart Apache instead with sudo systemctl restart apache2. CLI scripts read the file on every run, so no restart is needed there.

Step 7 of 8Run Multiple PHP Versions and Switch the Default

With the Sury repository, versions install side by side under /etc/php/X.Y/ and /usr/bin/phpX.Y, so you can keep, for example, PHP 8.6 for new sites and PHP 8.4 for an older application on the same server. Each FPM version runs as its own service (php8.6-fpm, php8.4-fpm) with its own socket, and each Nginx site can point at the socket it needs.

The php command on the command line is managed by the alternatives system. To change which version it runs:

sudo update-alternatives --config php

Or set it directly:

sudo update-alternatives --set php /usr/bin/php8.6

This changes only the CLI default (and with it Composer, cron jobs and scripts). Web servers keep using the module or socket you configured in Step 4 or Step 5. You can always call a version directly, for example php8.4 -v.

Step 8 of 8Test Your PHP Installation

Create a small test file in your web root:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Open http://your-server-ip/info.php in a browser. You should see the PHP information page with the version the web server actually uses (for example PHP Version 8.5.4 or 8.6.0) at the top, the loaded extensions and the active configuration file.

Once you have confirmed that everything works, delete the file. It exposes details about your server that are useful to an attacker:

sudo rm /var/www/html/info.php

Conclusion

Installing PHP on Ubuntu 26.04 LTS is simple. PHP 8.5 comes straight from Ubuntu’s repositories and gets security fixes with normal system updates. When you need the newer PHP 8.6, or an older branch such as 8.4 or 7.4, add the Sury repository at packages.sury.org and install the versioned packages side by side. You also added extensions, connected PHP to Apache or Nginx, tuned php.ini and verified the result in a browser.

Frequently Asked Questions (FAQs)

Which PHP version does Ubuntu 26.04 ship by default?

Ubuntu 26.04 LTS ships PHP 8.5. The unversioned php package depends on php8.5, and Canonical provides security updates for it for the life of the release. Run apt policy php8.5 to see the exact version your system offers.

How do I install PHP 8.6 on Ubuntu 26.04?

PHP 8.6 is not in Ubuntu’s repositories. Add the Sury repository as shown in Step 2 (Option B), then run sudo apt install php8.6-cli php8.6-fpm. Extensions follow the same naming, for example php8.6-mysql.

Can I use the ondrej/php PPA on Ubuntu 26.04?

Not yet. As of November 2026, the PPA publishes packages for Ubuntu 24.04 and 22.04 only. Adding it on 26.04 doesn’t break anything, but it doesn’t make any extra PHP versions available either. Use the Sury repository at packages.sury.org instead: it comes from the same maintainer and already has Ubuntu 26.04 builds. Don’t point the PPA at noble (Ubuntu 24.04) packages; mixing releases leads to dependency conflicts and broken upgrades.

What is the difference between mod_php and PHP-FPM?

mod_php embeds the PHP interpreter inside every Apache worker process. It is simple to set up, but it uses more memory and only works with Apache’s prefork MPM. PHP-FPM runs PHP as a separate pool of processes that the web server talks to over a socket. It works with both Apache and Nginx, uses less memory under load, and is the recommended choice for anything beyond a small personal server.

I upgraded from Ubuntu 24.04. Will PHP 8.5 break my website?

A release upgrade replaces Ubuntu 24.04’s PHP 8.3 with PHP 8.5, so test your application first. Code that already runs cleanly on PHP 8.4 usually needs little or no work, but older code, abandoned plugins and unmaintained libraries are the usual sources of trouble. Test on a staging copy of the server, run your test suite, and check the error log with error_reporting set to E_ALL before you upgrade production. If the application isn’t ready, install PHP 8.4 from the Sury repository and move it to 8.5 or 8.6 later.

How do I install extensions that are not in the list above?

Search the repository for the exact package name, then install it. For example:

apt search php8.5- | grep redis
sudo apt install php8.5-redis -y

Restart PHP-FPM or Apache afterwards so the new module is loaded, and confirm it with php -m. Extensions that have no package can still be built with pecl after installing php8.5-dev (or php8.6-dev).

Why does php -v show a different version than my website?

The php -v command reports the CLI binary, which is separate from what your site runs. With Apache, check which PHP module is enabled (ls /etc/apache2/mods-enabled | grep php). With Nginx, check that fastcgi_pass points at the socket of the version you want, such as /run/php/php8.6-fpm.sock. Restart the web server after any change, then load a phpinfo() page to confirm.

How do I remove a PHP version?

Purge the packages and remove the dependencies that are no longer needed (replace 8.5 with the version you want to remove):

sudo apt purge 'php8.5*' -y
sudo apt autoremove -y

The purge also removes your configuration files under /etc/php/8.5, so back up anything you customised first.

Do I need Composer?

Most modern PHP applications manage their dependencies with Composer. It is a PHP script and runs under whichever php binary is the default. See how to install Composer on Ubuntu.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top