PHP 8.5 is included in Ubuntu 26.04’s default repositories and is the recommended version for new PHP applications. Many popular tools including WordPress, Laravel, and Magento run on PHP, making it one of the first packages configured on LAMP and LEMP stacks.
This guide covers how to install PHP on Ubuntu 26.04 with both Apache and Nginx, how to add common extensions, and how to manage multiple PHP versions when your projects require more than one.
Prerequisite: You need sudo access. Have Apache or Nginx installed before following the web server integration steps.
Install PHP on Ubuntu 26.04 with Apache or Nginx
For Apache, install PHP and the Apache PHP module:
bash
sudo apt update<br>sudo apt install php libapache2-mod-php<br>The libapache2-mod-php package embeds the PHP interpreter directly into the Apache process. Restart Apache to load the module:
bash
sudo systemctl restart apache2<br>For Nginx, install PHP-FPM (FastCGI Process Manager). Nginx is a pure HTTP server with no built-in language support. PHP-FPM runs as a separate process pool and communicates with Nginx through a Unix socket — a more efficient model than spawning a new process for each request:
bash
sudo apt update<br>sudo apt install php-fpm<br>If apt cannot find php-fpm, the Universe repository may be disabled on your system. Enable it first:
bash
sudo add-apt-repository universe && sudo apt update && sudo apt install php-fpm<br>PHP-FPM starts automatically after installation. Add the following location block to your Nginx server block to pass PHP requests to FPM:
nginx
location ~ .php$ {<br>include snippets/fastcgi-php.conf;<br>fastcgi_pass unix:/run/php/php-fpm.sock;<br>}<br>The socket path /run/php/php-fpm.sock is a symlink managed by the alternatives system. If it does not exist, check the available sockets with ls -l /run/php/. Restart Nginx after saving the configuration:
bash
sudo systemctl restart nginx<br>Install PHP Extensions and Verify PHP is Working<br>Install extensions with:
bash
sudo apt install php-[extname]
Commonly needed extensions for web applications:
Extension Package Purpose<br>MySQL php-mysql MySQL and MariaDB database access<br>cURL php-curl URL transfers and API calls<br>GD php-gd Image processing<br>Mbstring php-mbstring Multibyte string handling<br>XML php-xml XML parsing<br>ZIP php-zip ZIP archive support<br>OPcache php-opcache Bytecode caching for performance<br>BCMath php-bcmath Arbitrary precision arithmetic<br>After installing an extension, restart Apache (sudo systemctl restart apache2) or PHP-FPM (sudo systemctl restart php8.5-fpm). Confirm what is loaded: php -m.
Verify PHP is working in the browser. Create a test file:
bash
echo '<?php phpinfo();' | sudo tee /var/www/html/info.php<br>Open http://your-server-ip/info.php. If PHP is configured correctly, you see the PHP information page. Remove this file immediately after testing — phpinfo() exposes your server's software versions, loaded extensions, and configuration values, all of which are useful information for attackers:
bash
sudo rm /var/www/html/info.php<br>Install Multiple PHP Versions and Switch Between Them<br>Ubuntu 26.04's default repositories carry only PHP 8.5. Ondřej Surý maintains a third-party repository at packages.sury.org that covers PHP 5.6 through 8.6 for Ubuntu 26.04. Note: the Launchpad PPA (ppa:ondrej/php) does not publish packages for Ubuntu 26.04 — you must use packages.sury.org directly:
bash
sudo apt install -y ca-certificates curl lsb-release<br>curl -fsSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb<br>sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb<br>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<br>sudo apt update<br>On Ubuntu 26.04, lsb_release -sc returns resolute, which selects the correct package set from the repository.
bash
sudo apt install php8.3 php8.3-cli php8.3-common php8.3-opcache php8.3-gd php8.3-curl php8.3-mysql php8.3-mbstring php8.3-xml<br>Switch the CLI default using the alternatives system:
bash
sudo update-alternatives --config php<br>Switch for Apache by disabling the current PHP module and enabling the target version:
bash
sudo a2dismod php8.5 && sudo a2enmod php8.3 && sudo systemctl restart apache2<br>Switch for Nginx: update the fastcgi_pass socket path in your server block to the versioned PHP-FPM socket (for example, unix:/run/php/php8.3-fpm.sock), then restart Nginx.
PHP 8.5 is now installed and integrated with your web server on Ubuntu 26.04. For framework-specific settings such as upload limits, memory, and OPcache tuning, edit the relevant php.ini file at /etc/php/8.5/fpm/php.ini for Nginx or /etc/php/8.5/apache2/php.ini for Apache, and restart the service. Leave a comment below if you have any questions.