How To

Install PHP on Ubuntu 26.04: Apache, Nginx, and Multiple Versions

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 &amp;&amp; sudo apt update &amp;&amp; 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 '&lt;?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.

Install a specific PHP version, for example PHP 8.3:

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 &amp;&amp; sudo a2enmod php8.3 &amp;&amp; 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.

Cyber Defence

Recent Posts

Upgrade to Ubuntu 26.04 from 25.10 and 24.04 LTS: Complete Guide

Ubuntu 26.04 LTS "Resolute Raccoon" arrived on April 23, 2026 with Linux kernel 7.0, GNOME 50,…

2 hours ago

Install Kubernetes on Ubuntu 26.04 with kubeadm and containerd

Kubernetes is the standard platform for running containerized workloads across multiple servers with self-healing, rolling…

2 hours ago

Install Ubuntu 26.04: Bootable USB, Partitioning, and First Steps

Ubuntu 26.04 LTS "Resolute Raccoon" was released on April 23, 2026 with Linux kernel 7.0, GNOME desktop, and standard security support until April 2031. A clean install gives you a known-good starting point on new hardware, when replacing another operating system, or when an upgrade path is not practical. This guide walks through how to install Ubuntu 26.04: downloading and verifying the ISO, writing a bootable USB drive, completing the installer, and doing the initial setup after the first boot. Before you start: You need a USB drive with at least 12 GB of free space. Back up any existing data on the target machine — the installer can erase the entire disk. Install Ubuntu 26.04: Download the ISO…

2 hours ago

Change Timezone on Ubuntu: timedatectl and Desktop GUI Guide

The correct timezone affects more than the clock on your screen. It drives cron job scheduling, systemd timer execution, log file timestamps, database record timing, and SSL certificate validity checks. A mismatched timezone can cause scheduled jobs to fire at the wrong hour and make log timestamps impossible to match with real-world events. This guide shows how to change timezone on Ubuntu using the timedatectl command (the recommended approach for servers and remote machines) and through the graphical Date & Time settings on desktop systems. The steps apply to all current Ubuntu releases including 24.04 and 26.04. <strong>Prerequisite:</strong>&nbsp;Only&nbsp;the&nbsp;root&nbsp;user&nbsp;or&nbsp;a&nbsp;user&nbsp;with&nbsp;sudo&nbsp;access&nbsp;can&nbsp;change&nbsp;the&nbsp;system&nbsp;timezone. Check the Current Timezone Before You Change It Run timedatectl with no arguments to see the active timezone and clock status: bashtimedatectl Sample output: Local…

2 hours ago

Install Atom on Ubuntu 18.04: GitHub’s Code Editor APT Setup

Atom is a free, open-source, cross-platform code editor developed by GitHub. Built on Electron, it uses…

14 hours ago

Install MariaDB on Ubuntu 18.04: Two Methods and Secure Setup

MariaDB is an open-source, multi-threaded relational database management system and a fully backward-compatible replacement for MySQL.…

1 day ago