Install PHP 8.4 on Ubuntu when your application targets property hooks, asymmetric visibility, the #[\Deprecated] attribute, or a PHP 8.4 compatibility window before moving to a newer branch. Ubuntu 26.04 defaults to PHP 8.5, Ubuntu 24.04 defaults to PHP 8.3, and Ubuntu 22.04 defaults to PHP 8.1, so PHP 8.4 installs from Ondrej Sury’s APT repository at packages.sury.org for the php8.4 package family across all three supported LTS releases.
The Sury source is a third-party APT repository, not the older Launchpad PPA. It gives Ubuntu 26.04, 24.04, and 22.04 a consistent PHP 8.4 install path with co-installable PHP branches for staged application upgrades. PHP 8.4 remains in active support through December 31, 2026, and security support through December 31, 2028, according to PHP’s supported versions table.
Install PHP 8.4 on Ubuntu
The Sury repository is the PHP 8.4 source for Ubuntu 26.04, 24.04, and 22.04. If you prefer the default branch that Ubuntu ships for your release, use the default PHP on Ubuntu instead.
Avoid one-off .deb downloads for this PHP branch. PHP applications usually need matching CLI, FPM, Apache, and extension packages, and a single APT source keeps those packages on the same update path.
Refresh APT and Confirm the Ubuntu Codename
Start with current package metadata, then confirm the release codename and architecture. The source file uses the codename in the Suites: field, and Sury’s PHP 8.4 package indexes currently provide the required package set for Ubuntu 26.04 on amd64 and arm64, plus Ubuntu 24.04 and 22.04 on amd64, arm64, and armhf.
sudo apt update
These package-management commands need sudo privileges. If your account cannot use sudo yet, add it with Add a New User to Sudoers on Ubuntu before continuing.
grep '^VERSION_CODENAME=' /etc/os-release
dpkg --print-architecture
VERSION_CODENAME=resolute amd64
Ubuntu 26.04 uses resolute, Ubuntu 24.04 uses noble, and Ubuntu 22.04 uses jammy. Ubuntu supports additional architectures, but the Sury PHP indexes for this PHP 8.4 workflow currently cover the architecture combinations guarded below.
Add the Sury PHP Repository on Ubuntu
Install the small prerequisite set, then save the Sury signing key as a binary keyring. The curl command in Linux guide explains the -fsSLo flags if you want to adapt this repository download pattern later.
sudo apt install -y ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
Load Ubuntu’s release metadata in the current shell and check the host before writing the source file.
. /etc/os-release
ARCH="$(dpkg --print-architecture)"
printf 'Using suite: %s\nUsing architecture: %s\n' "$VERSION_CODENAME" "$ARCH"
Using suite: resolute Using architecture: amd64
Create the DEB822 source file. The guarded block stops before writing anything when the host does not match a validated Ubuntu release and Sury package-index combination.
. /etc/os-release
ARCH="$(dpkg --print-architecture)"
case "$VERSION_CODENAME:$ARCH" in
resolute:amd64|resolute:arm64|noble:amd64|noble:arm64|noble:armhf|jammy:amd64|jammy:arm64|jammy:armhf)
printf '%s\n' \
'Types: deb' \
'URIs: https://packages.sury.org/php/' \
"Suites: $VERSION_CODENAME" \
'Components: main' \
"Architectures: $ARCH" \
'Signed-By: /usr/share/keyrings/deb.sury.org-php.gpg' | sudo tee /etc/apt/sources.list.d/php.sources > /dev/null
;;
*)
printf 'This workflow covers Ubuntu 26.04 on amd64/arm64 and Ubuntu 24.04/22.04 on amd64/arm64/armhf; this host reports %s/%s.\n' "$VERSION_CODENAME" "$ARCH" >&2
false
;;
esac
Refresh APT after adding the Sury source.
sudo apt update
Confirm that php8.4 is available from Sury.
apt-cache policy php8.4
php8.4:
Installed: (none)
Candidate: 8.4.21-1+0~20260507.47+ubuntu26.04~1.gbp181673
Version table:
8.4.21-1+0~20260507.47+ubuntu26.04~1.gbp181673 500
500 https://packages.sury.org/php resolute/main amd64 Packages
The version string and suite change by release. Ubuntu 24.04 shows
ubuntu24.04andnoble, while Ubuntu 22.04 showsubuntu22.04andjammy. On Ubuntu 26.04, PHP 8.4 comes from Sury because the Ubuntu archive default is PHP 8.5.
Compare PHP 8.4 Web Server Setups on Ubuntu
Choose the integration that matches the web server already running on the host. If the server layer is not installed yet, start with Install Apache on Ubuntu or Install Nginx on Ubuntu first.
| Setup | Packages | Best For | Trade-off |
|---|---|---|---|
| Apache with mod_php | apache2, libapache2-mod-php8.4, php8.4-cli | Short-lived labs and simple local development | Apache runs PHP inside its worker model |
| Apache with PHP-FPM | apache2, php8.4-fpm, php8.4-cli | Production Apache sites that need separate PHP worker pools | Requires Apache proxy and FPM configuration |
| Nginx with PHP-FPM | nginx, php8.4-fpm, php8.4-cli | LEMP stacks and high-traffic PHP sites | Nginx needs a FastCGI block that points at the PHP 8.4 socket |
PHP-FPM is the better default for production because it keeps PHP in a separate service with its own pool settings, logs, and restart path. Use mod_php only when you need the shortest Apache-only setup for a local or disposable host.
If your target is a container image such as php:8.4-apache or php:8.4-fpm, treat that as a Docker workflow rather than an Ubuntu APT package name. Set up Docker on Ubuntu first, then use the official PHP image tag in your container or Compose configuration.
Install PHP 8.4 with Apache mod_php on Ubuntu
The mod_php path loads PHP as an Apache module. It is convenient for quick development stacks but is less flexible than PHP-FPM.
sudo apt install -y apache2 libapache2-mod-php8.4 php8.4-cli
sudo systemctl restart apache2
Confirm that Apache loaded the PHP module.
sudo /usr/sbin/apache2ctl -M 2>/dev/null | grep php
php_module (shared)
Install PHP 8.4 with Apache and PHP-FPM on Ubuntu
This setup keeps Apache in front while PHP runs through the dedicated php8.4-fpm service.
sudo apt install -y apache2 php8.4-fpm php8.4-cli
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.4-fpm
sudo systemctl enable php8.4-fpm --now
sudo systemctl restart apache2
If you previously tested
libapache2-mod-php8.4on the same host, disable mod_php withsudo a2dismod php8.4before enabling the FPM configuration.
Check the FPM service, socket, and Apache configuration state.
systemctl is-active php8.4-fpm
test -S /run/php/php8.4-fpm.sock && echo 'php8.4-fpm socket exists'
sudo /usr/sbin/apache2ctl -M 2>/dev/null | grep proxy_fcgi
test -L /etc/apache2/conf-enabled/php8.4-fpm.conf && echo 'php8.4-fpm configuration enabled'
active php8.4-fpm socket exists proxy_fcgi_module (shared) php8.4-fpm configuration enabled
Install PHP 8.4 with Nginx and PHP-FPM on Ubuntu
Nginx always hands PHP requests to FastCGI, so install the FPM service and CLI package together.
sudo apt install -y nginx php8.4-fpm php8.4-cli
sudo systemctl enable php8.4-fpm --now
Add this location block to the relevant Nginx server block so PHP requests reach the PHP 8.4 socket.
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}
Check the service state, confirm that the socket exists, then test the Nginx configuration before reloading the service.
systemctl is-active php8.4-fpm
test -S /run/php/php8.4-fpm.sock && echo 'php8.4-fpm socket exists'
sudo nginx -t
active php8.4-fpm socket exists nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl reload nginx
Verify the PHP 8.4 CLI on Ubuntu
Confirm the installed interpreter version before moving on to extensions or application setup.
php8.4 --version
PHP 8.4.21 (cli) (built: May 7 2026 22:31:12) (NTS)
Copyright (c) The PHP Group
Built by Ubuntu
Zend Engine v4.4.21, Copyright (c) Zend Technologies
with Zend OPcache v8.4.21, Copyright (c), by Zend Technologies
Install PHP 8.4 Extensions on Ubuntu
Most PHP applications need extra modules beyond the base interpreter. The package set here covers common requirements for WordPress, Laravel, API clients, database access, image handling through GD, ZIP archives, XML processing, SOAP clients, and multibyte text.
Install Common PHP 8.4 Extensions on Ubuntu
Install the modules your application needs. The grouped list uses PHP 8.4 packages verified across the guarded Sury suite and architecture combinations above.
sudo apt install -y php8.4-curl php8.4-mysql php8.4-gd php8.4-zip php8.4-intl php8.4-bcmath php8.4-readline php8.4-mbstring php8.4-xml php8.4-soap
APCu is useful for application-level caching, but Sury does not publish php8.4-apcu for every supported architecture combination. Check for a candidate before installing it.
apt-cache policy php8.4-apcu
if apt-cache policy php8.4-apcu | grep -q 'Candidate: (none)'; then
printf 'php8.4-apcu is not available for this Ubuntu release and architecture.\n'
else
sudo apt install -y php8.4-apcu
fi
JSON and Tokenizer support are bundled with PHP 8.4 packages, so do not install nonexistent
php8.4-jsonorphp8.4-tokenizerpackages. Zend OPcache is packaged asphp8.4-opcacheand is normally pulled in with the base CLI/FPM packages.
Restart the PHP handler after installing extensions so web requests load the new modules.
sudo systemctl restart php8.4-fpm
If the host uses Apache with mod_php instead of PHP-FPM, restart Apache with
sudo systemctl restart apache2instead.
Verify a few commonly needed modules and confirm that OPcache is active in the CLI build.
php8.4 -m | grep -E '^(curl|gd|mbstring|mysqli|xml)$'
php8.4 --version | grep 'Zend OPcache'
curl
gd
mbstring
mysqli
xml
with Zend OPcache v8.4.21, Copyright (c), by Zend Technologies
Search Available PHP 8.4 Extensions on Ubuntu
Search the active package sources before adding optional modules such as Redis, Memcached, Imagick, Xdebug, or PCOV. Availability differs by Ubuntu release, architecture, and repository source.
apt-cache pkgnames php8.4- | sort | head -n 6
On the amd64 validation path, relevant output includes package names like these.
php8.4-amqp php8.4-apcu php8.4-ast php8.4-bcmath php8.4-bz2 php8.4-cgi
If a searched extension has Candidate: (none), do not mix the old Launchpad PPA into this setup just to satisfy one package name. Keep one PHP source active, then choose an extension path that your application supports.
Before accepting an extension install transaction, review any removals APT proposes. Existing generic packages such as php-imagick can belong to an older PHP branch or a different source, and removing them may affect sites that still use that branch.
Install PHP 8.4 Development Headers on Ubuntu
Install php8.4-dev only on development hosts that compile PHP extensions or need tools such as phpize. It pulls compiler and packaging dependencies that are usually unnecessary on production web servers.
sudo apt install -y php8.4-dev
Verify the development helper reports the PHP 8.4 API branch.
phpize8.4 --version
Configuring for: PHP Version: 8.4 PHP Api Version: 20240924 Zend Module Api No: 20240924 Zend Extension Api No: 420240924
Configure PHP 8.4 on Ubuntu
PHP keeps separate configuration trees for the CLI and FPM SAPIs. CLI changes affect terminal scripts, while FPM changes affect web applications served through Apache with FPM or Nginx.
Locate PHP 8.4 Configuration Files on Ubuntu
Check the CLI configuration path first.
php8.4 --ini | head -3
Configuration File (php.ini) Path: "/etc/php/8.4/cli" Loaded Configuration File: "/etc/php/8.4/cli/php.ini" Scan for additional .ini files in: "/etc/php/8.4/cli/conf.d"
For web workloads that use PHP-FPM, edit /etc/php/8.4/fpm/php.ini and restart php8.4-fpm after changes.
Adjust PHP 8.4 FPM Settings on Ubuntu
Open the FPM configuration file for web-facing settings such as upload limits, memory limits, and execution timeouts.
sudo nano /etc/php/8.4/fpm/php.ini
Common production values look like this, but tune them for the application and available memory.
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
max_execution_time = 120
max_input_vars = 3000
display_errors = Off
expose_php = Off
Restart PHP-FPM and verify the saved values directly from the FPM configuration file.
sudo systemctl restart php8.4-fpm
grep -E '^(upload_max_filesize|post_max_size|memory_limit|max_execution_time|max_input_vars|display_errors|expose_php)' /etc/php/8.4/fpm/php.ini
upload_max_filesize = 64M post_max_size = 64M memory_limit = 256M max_execution_time = 120 max_input_vars = 3000 display_errors = Off expose_php = Off
For a deeper FPM pool walkthrough, use Configure PHP-FPM on Ubuntu after the PHP 8.4 packages are installed.
Run Multiple PHP Versions on Ubuntu
Sury packages PHP branches independently, so PHP 8.4 can coexist with PHP 8.5, PHP 8.3, or the release default branch. Keep CLI, Apache, and Nginx switching separate because each layer chooses its PHP version differently.
Switch the PHP CLI Version on Ubuntu
Use update-alternatives to select which installed PHP binary responds to the unversioned php command.
sudo update-alternatives --config php
The menu only lists PHP branches installed on that host. Choose the entry that points to /usr/bin/php8.4 when PHP 8.4 should be the default CLI interpreter.
Set PHP 8.4 directly when you do not need the interactive menu.
sudo update-alternatives --set php /usr/bin/php8.4
php --version
Switch Apache to PHP 8.4 on Ubuntu
For Apache with mod_php, disable any older PHP module that is currently enabled, then enable PHP 8.4.
for module in php8.1 php8.3 php8.5; do
if sudo a2query -m "$module" >/dev/null 2>&1; then
sudo a2dismod "$module"
fi
done
sudo a2enmod php8.4
sudo systemctl reload apache2
Switch Apache PHP-FPM to PHP 8.4 on Ubuntu
For Apache with PHP-FPM, switch the enabled FPM configuration instead of the mod_php module.
for conf in php8.1-fpm php8.3-fpm php8.5-fpm; do
if sudo a2query -c "$conf" >/dev/null 2>&1; then
sudo a2disconf "$conf"
fi
done
sudo a2enconf php8.4-fpm
sudo systemctl reload apache2
Switch Nginx PHP-FPM to PHP 8.4 on Ubuntu
For Nginx, update the fastcgi_pass socket in the relevant server block and reload Nginx after the syntax check passes.
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
sudo nginx -t
sudo systemctl reload nginx
Compare PHP Versions on Ubuntu
Use PHP 8.4 when your application has been certified for that branch or needs its feature set without jumping to PHP 8.5 yet. Ubuntu’s default PHP branch still matters for systems that prioritize archive-only maintenance over third-party repositories.
| PHP Version | Availability on Ubuntu | Best Fit | Trade-off |
|---|---|---|---|
| Default PHP | Ubuntu archive branch, currently PHP 8.5 on 26.04, PHP 8.3 on 24.04, and PHP 8.1 on 22.04 | Systems that prefer Ubuntu archive packages and minimal third-party sources | Branch changes by Ubuntu release |
| PHP 8.5 | Ubuntu 26.04 archive and Sury packages for all supported LTS releases | New projects that can use the current PHP feature branch | Newer application compatibility target |
| PHP 8.4 | Sury packages for Ubuntu 26.04, 24.04, and 22.04 | Applications certified for PHP 8.4 or staged upgrades from PHP 8.1/8.3 | Requires the third-party Sury repository in this article |
| PHP 8.3 | Ubuntu 24.04 archive and Sury packages | Applications that need a stable branch with broad current framework support | Older feature set than PHP 8.4 and 8.5 |
| PHP 8.2 | Sury packages for supported Ubuntu LTS releases | Legacy applications that have not moved past PHP 8.2 | Security-only branch nearing end of security support |
Review PHP 8.4 Feature Highlights
PHP 8.4 introduced property hooks, so classes can attach get and set logic directly to properties instead of routing every access through separate getter and setter methods. Asymmetric visibility lets a property be public for reads but private or protected for writes, which helps with immutable-style APIs.
The #[\Deprecated] attribute marks functions or methods as deprecated with custom messages and version information. PHP 8.4 also added improved DOM classes such as \Dom\HTMLDocument and \Dom\XMLDocument, plus array helpers like array_find(), array_find_key(), array_any(), and array_all(). For the full upstream change list, use the official PHP 8.4 release announcement.
Update or Remove PHP 8.4 on Ubuntu
APT owns both the Sury repository packages and Ubuntu’s own PHP packages, so routine updates and removals should stay inside APT.
Update PHP 8.4 on Ubuntu
Refresh package metadata, then upgrade the installed PHP 8.4 package family without forcing unrelated packages into the same transaction.
sudo apt update
sudo apt install --only-upgrade 'php8.4*'
Restart PHP-FPM when the host uses FPM for web requests.
sudo systemctl restart php8.4-fpm
php8.4 --version
Remove PHP 8.4 Packages from Ubuntu
Remove the PHP 8.4 branch packages while preserving other PHP versions and the repository source.
sudo apt remove 'php8.4*'
Use purge only when you also want to remove package-managed configuration under /etc/php/8.4/. Back up edited php.ini files or pool files first.
sudo apt purge 'php8.4*'
Review orphaned dependencies before deleting them. Reused systems may already have unrelated autoremovable packages.
sudo apt autoremove --dry-run
Continue only when the preview lists packages you intend to remove.
sudo apt autoremove
Remove the Sury PHP Repository from Ubuntu
Remove the Sury source and signing key only when no remaining PHP branch on the host depends on that repository for updates.
sudo rm -f /etc/apt/sources.list.d/php.sources /usr/share/keyrings/deb.sury.org-php.gpg
sudo apt update
apt-cache policy php8.4
After removing Sury, apt-cache policy php8.4 should no longer show a candidate from packages.sury.org. Ubuntu 26.04, 24.04, and 22.04 do not provide the same PHP 8.4 package path from their default archives.
Troubleshoot PHP 8.4 on Ubuntu
Fix Duplicate PHP Repository Sources on Ubuntu
APT should have one PHP branch source at a time. Check for older Launchpad PPA files and older Sury one-line source files before installing or updating PHP 8.4, because mixed source files can make candidates confusing or trigger Signed-By conflicts.
grep -R -E "ondrej/php|packages[.]sury[.]org/php" /etc/apt/sources.list /etc/apt/sources.list.d/ 2>/dev/null
A duplicate Sury layout can look like this, with both the DEB822 file created earlier and an older one-line php.list entry.
/etc/apt/sources.list.d/php.sources:URIs: https://packages.sury.org/php/ /etc/apt/sources.list.d/php.list:deb [signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ noble main
If both files point to packages.sury.org/php, keep the DEB822 php.sources file created earlier and disable the older one-line file.
if [ -f /etc/apt/sources.list.d/php.list ]; then
sudo mv /etc/apt/sources.list.d/php.list /etc/apt/sources.list.d/php.list.disabled
fi
sudo apt update
If APT still contacts an older Launchpad PHP source, remove that source before using the Sury packages.sury.org entry.
sudo add-apt-repository --remove ppa:ondrej/php -y
sudo apt update
If add-apt-repository is unavailable or the old file was edited manually, use Remove a PPA from Ubuntu to identify and remove the leftover source safely.
Fix Unable to Locate php8.4-json or php8.4-tokenizer on Ubuntu
APT reports no candidate for php8.4-json or php8.4-tokenizer because those are not separate installable Sury packages for PHP 8.4.
E: Unable to locate package php8.4-json E: Couldn't find any package by glob 'php8.4-json'
Install the base CLI package and common files instead.
sudo apt install -y php8.4-cli php8.4-common
Then check the bundled modules.
php8.4 -m | grep '^tokenizer$'
php8.4 --version | grep 'Zend OPcache'
tokenizer
with Zend OPcache v8.4.21, Copyright (c), by Zend Technologies
Fix Optional Extension Candidate Missing on Ubuntu
Some extension package names that existed in older Launchpad-based PHP guides do not have candidates in the direct Sury packages.sury.org source for every release and architecture. Check the candidate before adding an optional extension to a production build.
apt-cache policy php8.4-redis
php8.4-redis: Installed: (none) Candidate: (none) Version table:
When a required extension has no candidate, keep the PHP repository setup consistent and choose a supported extension path for that application instead of adding a second PHP repository beside Sury.
Fix the PHP-FPM Socket Not Found Error on Ubuntu
If Nginx returns a 502 Bad Gateway error, check the Nginx error log for a missing PHP-FPM socket. The tail command in Linux is useful for reading the newest log lines without opening the full file.
sudo tail -5 /var/log/nginx/error.log
connect() to unix:/run/php/php8.4-fpm.sock failed (2: No such file or directory) while connecting to upstream
Confirm the service is active and the socket exists.
systemctl is-active php8.4-fpm
test -S /run/php/php8.4-fpm.sock && echo 'php8.4-fpm socket exists'
active php8.4-fpm socket exists
Start PHP-FPM if the service is inactive, then test and reload Nginx.
sudo systemctl enable php8.4-fpm --now
sudo nginx -t
sudo systemctl reload nginx
Fix the Wrong PHP Version on Ubuntu
If php --version still reports another branch, set the CLI alternative to PHP 8.4.
sudo update-alternatives --set php /usr/bin/php8.4
Verify the active binary after changing the alternative.
command -v php
php --version
/usr/bin/php PHP 8.4.21 (cli) (built: May 7 2026 22:31:12) (NTS)
Conclusion
PHP 8.4 is now installed on Ubuntu through the Sury APT repository, with Apache or Nginx connected through the handler that matches your stack. For common next steps, add Composer on Ubuntu, deploy WordPress with Nginx and MariaDB on Ubuntu, or tune Nginx FastCGI Cache on Ubuntu.


Thank you, installed php8.4 quickly on updated 22.04