How to Install PHP on Ubuntu 26.04

PHP is one of the most used server-side programming languages. Many popular CMS and frameworks such as WordPress, Magento, and Laravel are written in PHP.
This guide covers the steps necessary to install PHP on Ubuntu 26.04 and integrate it with Nginx and Apache. The default Ubuntu 26.04 repositories include PHP 8.5. We will also show you how to install other PHP versions.
Quick Reference
For a printable quick reference, see the PHP cheatsheet .
| Task | Command |
|---|---|
| Install PHP with Apache | sudo apt install php libapache2-mod-php |
| Install PHP 8.5 with Nginx | sudo apt install php8.5-fpm |
| Install an extension | sudo apt install php-[extname] |
| Check PHP version (CLI) | php -v |
| List loaded PHP modules (CLI) | php -m |
| Restart PHP-FPM | sudo systemctl restart php8.5-fpm |
| Check PHP-FPM socket | ls -l /run/php/ |
| Install PHP 8.4 (Sury repository) | sudo apt install php8.4-fpm |
| Switch PHP version (CLI) | sudo update-alternatives --config php |
Prerequisites
To follow this guide, you need to be logged in as a user with sudo privileges .
Installing PHP 8.5 with Apache
If you are using Apache as your web server, run the following commands to install PHP and the Apache PHP module:
sudo apt update
sudo apt install php libapache2-mod-phpOnce the packages are installed, restart Apache for the PHP module to get loaded:
sudo systemctl restart apache2Installing PHP 8.5 with Nginx
Unlike Apache, Nginx does not have built-in support for processing PHP files. We will use PHP-FPM (FastCGI Process Manager) to handle PHP files.
Run the following commands to install PHP 8.5 and its PHP-FPM service:
sudo apt update
sudo apt install php8.5-fpmIf apt cannot locate php8.5-fpm, make sure the Universe repository is enabled. Standard Ubuntu installations usually include it, but minimal images may have only the core repository components enabled:
sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update
sudo apt install php8.5-fpmOnce the installation is completed, the FPM service starts automatically. To check the status of the service, run:
sudo systemctl status php8.5-fpm● php8.5-fpm.service - The PHP 8.5 FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php8.5-fpm.service; enabled; preset: enabled)
Active: active (running) since Tue 2026-12-01 21:26:35 UTC; 2s agoenabled means the service starts at boot, and active (running) confirms that PHP-FPM is running.
You can now edit the Nginx server block and add the following lines so that Nginx can process PHP files:
server {
# . . . other code
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
}
}The versioned socket keeps this server block tied to PHP 8.5. To check which sockets are available, run:
ls -l /run/php/Restart the Nginx service so that the new configuration takes effect:
sudo systemctl restart nginxInstalling PHP Extensions
PHP extensions are compiled libraries that extend the core functionality of PHP. Extensions are available as packages and can be easily installed with apt
:
sudo apt install php-[extname]For example, to install the MySQL and GD extensions, run:
sudo apt install php-mysql php-gdHere are some of the most commonly used PHP extensions:
| Extension | Package | Description |
|---|---|---|
| MySQL | php-mysql | MySQL and MariaDB database support |
| cURL | php-curl | URL transfer library |
| GD | php-gd | Image processing |
| Mbstring | php-mbstring | Multibyte string support |
| XML | php-xml | XML parsing and manipulation |
| ZIP | php-zip | ZIP archive support |
| Intl | php-intl | Internationalization functions |
| BCMath | php-bcmath | Arbitrary precision math |
OPcache does not need a separate package. Since PHP 8.5, it is part of the PHP core, and php -v reports it as with Zend OPcache.
To install all commonly needed extensions at once:
sudo apt install php-mysql php-curl php-gd php-mbstring php-xml php-zip php-intl php-bcmathAfter installing a new PHP extension, restart Apache or PHP-FPM depending on your setup:
sudo systemctl restart apache2Or for Nginx with PHP-FPM:
sudo systemctl restart php8.5-fpmTo list the modules loaded by the current command-line version of PHP, run:
php -mTo see which extensions Apache or PHP-FPM loads for your site, use the browser test below.
Testing PHP Processing
To confirm that the web server can process PHP files, create a new info.php file in the document root of the site you configured. The default site uses /var/www/html. If your site uses a different directory, substitute it in both commands below:
echo '<?php phpinfo();' | sudo tee /var/www/html/info.phpOpen /info.php in your browser using the hostname of the site you configured, for example https://example.com/info.php. If you are testing the default site by IP, use http://your_server_ip/info.php. If PHP is configured correctly, the information page shows the PHP version and extensions loaded for that request:

The phpinfo() page exposes details about your server and PHP configuration. Remove it after testing:
sudo rm /var/www/html/info.phpInstalling Other PHP Versions
Ondřej Surý, a Debian developer, maintains a repository that includes multiple PHP versions. His ppa:ondrej/php PPA is frozen and has no packages for Ubuntu 26.04. The PHP packages for Ubuntu are now published at packages.sury.org. This is a third-party source, so use it only if you need a different PHP version than what Ubuntu provides. To enable the repository
, run:
sudo apt install -y ca-certificates curl lsb-release
curl -fsSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb
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 updateOn Ubuntu 26.04 lsb_release -sc returns resolute. The repository carries PHP 5.6 through 8.6 for this release.
After you add the repository, APT can replace Ubuntu’s PHP 8.5 packages with Sury’s builds on the next upgrade. Sury’s unversioned packages, such as php-fpm and php-mysql, currently track PHP 8.6. If APT upgrades an installed php-fpm metapackage during the PHP 8.4 installation, it also installs php8.6-fpm.
Use versioned package names to select a PHP branch. For example, to preview installing PHP 8.4 with PHP-FPM and a few common extensions, run:
sudo apt -s install php8.4-fpm php8.4-cli php8.4-opcache php8.4-gd php8.4-curl php8.4-mysql php8.4-mbstring php8.4-xmlCheck which packages APT would install, upgrade, or remove. If the changes match what you want, run the installation:
sudo apt install php8.4-fpm php8.4-cli php8.4-opcache php8.4-gd php8.4-curl php8.4-mysql php8.4-mbstring php8.4-xmlPHP 8.4 still ships OPcache as a separate php8.4-opcache package. On an Apache server, replace php8.4-fpm with libapache2-mod-php8.4.
Use php8.4-fpm on Nginx servers. When none of the alternatives for the php8.4 metapackage is installed, APT can select the Apache module and pull in Apache alongside Nginx.
Switching Between PHP Versions
In automatic mode, update-alternatives points the php command to the highest-priority installed CLI version. To select PHP 8.4 manually, run:
sudo update-alternatives --set php /usr/bin/php8.4To interactively choose the default version:
sudo update-alternatives --config phpFor Apache, disable the current PHP module and enable the one you want:
sudo a2dismod php8.5
sudo a2enmod php8.4
sudo systemctl restart apache2For Nginx, update the PHP-FPM socket path in your server block to point to the correct version:
fastcgi_pass unix:/run/php/php8.4-fpm.sock;Then restart Nginx:
sudo systemctl restart nginxChecking the PHP Version
To check which PHP version the php command uses, run:
php -vPHP 8.5.4 (cli) (built: Nov 19 2026 00:22:49) (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 TechnologiesThe first line shows the PHP release and cli, the command-line build. For other ways to find the version, including from a web page, see how to check the PHP version
.
PHP Configuration Files
PHP configuration files are located at:
- Main config:
/etc/php/8.5/cli/php.ini(CLI) and/etc/php/8.5/apache2/php.ini(Apache) or/etc/php/8.5/fpm/php.ini(FPM) - FPM pool config:
/etc/php/8.5/fpm/pool.d/www.conf - Extension configs:
/etc/php/8.5/mods-available/
After changing any configuration, restart the relevant service:
sudo systemctl restart php8.5-fpmUninstalling PHP
Purging PHP removes its package configuration files and can remove packages that depend on it. To preview removing PHP 8.5 from the Nginx setup, run:
sudo apt -s purge php8.5-fpm php8.5-cli php8.5-commonFor the Apache setup, replace php8.5-fpm with libapache2-mod-php8.5 in both commands. If the preview lists only packages you want to remove, run the purge:
sudo apt purge php8.5-fpm php8.5-cli php8.5-commonIf you also want to remove unused dependencies, review the list with sudo apt -s autoremove before running sudo apt autoremove.
Troubleshooting
Unable to locate package php8.4
Ubuntu 26.04 ships only PHP 8.5. Other versions such as PHP 8.4 or 8.3 come from the Sury repository. The ppa:ondrej/php PPA used in older guides is frozen and has no packages for Ubuntu 26.04. If you added it, remove it and enable the packages.sury.org repository as shown in the Installing Other PHP Versions section:
sudo add-apt-repository --remove ppa:ondrej/phpPackage ‘php-opcache’ has no installation candidate
OPcache is built into PHP 8.5, and Ubuntu 26.04 no longer has a separate php-opcache package. Remove it from your apt install command. Older versions from the Sury repository still use versioned packages such as php8.4-opcache.
502 Bad Gateway in Nginx
Compare the fastcgi_pass path in your server block with the sockets in /run/php/. If the shared php-fpm.sock link is missing, use the versioned socket. For PHP 8.5, use /run/php/php8.5-fpm.sock and check the service with sudo systemctl status php8.5-fpm. For other causes, see how to fix 502 Bad Gateway in Nginx
.
FAQ
What PHP version does Ubuntu 26.04 include?
Ubuntu 26.04 ships with PHP 8.5 in its default repositories.
Why does Ubuntu 26.04 have PHP 8.5.4 when newer 8.5 releases exist?
Ubuntu keeps the PHP version it shipped with for the life of the release. Security fixes are backported into it. The package version (for example, 8.5.4-0ubuntu1.6) changes, but the upstream version stays at 8.5.4. If you need the latest upstream point release, the Sury repository carries current PHP 8.5 builds.
What is the difference between php and php-fpm?
The php metapackage installs the default PHP version and can use the Apache module, PHP-FPM, or CGI. The php-fpm metapackage selects PHP-FPM for the default PHP version, which Nginx can use to process PHP requests. For command-line PHP alone, install php-cli.
Can I run multiple PHP versions at the same time?
Yes. You can install multiple PHP versions from the Ondřej Surý packages.sury.org repository and configure each virtual host or server block to use a different PHP version.
Do I need to restart Apache or Nginx after installing an extension?
Yes. After installing a PHP extension, restart Apache (sudo systemctl restart apache2) or PHP-FPM (sudo systemctl restart php8.5-fpm) for the extension to be loaded.
Where is the php.ini file located?
PHP uses separate php.ini files for each SAPI. The CLI config is at /etc/php/8.5/cli/php.ini, the Apache config at /etc/php/8.5/apache2/php.ini, and the FPM config at /etc/php/8.5/fpm/php.ini.
Conclusion
We have shown you how to install PHP 8.5 on Ubuntu 26.04 with both Apache and Nginx. To set up a full web stack, see our guides on installing LAMP and LEMP on Ubuntu 26.04.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page