PHP 8.4 introduces property hooks for cleaner getter/setter logic, asymmetric visibility for type-safe property access, and the #[\Deprecated] attribute for explicit deprecation warnings. These features reduce boilerplate code and improve API maintainability. On Ubuntu 26.04 LTS, PHP 8.4 ships in the default repositories. On Ubuntu 24.04 LTS and 22.04 LTS, PHP 8.4 is available through Ondrej Sury’s PHP PPA, which provides co-installable PHP versions with regular security updates.
This guide covers adding the Sury PPA (when required), installing PHP 8.4 with Apache or Nginx, configuring PHP-FPM for production workloads, and managing extensions. After completing these steps, you will have PHP 8.4 configured and ready to power WordPress, Laravel, or any application that benefits from property hooks and improved DOM handling.
Select a PHP Version for Your Ubuntu System
Compare PHP Versions Available for Ubuntu
Ubuntu repositories and the Sury PPA provide different PHP versions targeting distinct use cases. The comparison below helps you decide which release fits your project requirements and maintenance preferences.
| PHP Version | Primary Focus | Support Status | Best For | Trade-offs |
|---|---|---|---|---|
| PHP (Distro Default) | Stability with Ubuntu security team maintenance | Matches Ubuntu release lifecycle | Production servers prioritizing official Ubuntu updates and minimal external dependencies | Version varies by release (8.4 on 26.04, 8.3 on 24.04, 8.1 on 22.04) |
| PHP 8.5 | URI extension, pipe operator, clone with properties | Active support through December 2027; security through December 2029 | Modern applications using functional programming patterns, URL parsing, and immutable object patterns | Requires Sury PPA on all Ubuntu LTS releases |
| PHP 8.4 | Property hooks, asymmetric visibility, #[\Deprecated] attribute | Active support through December 2026; security through December 2028 | Production applications using modern OOP patterns, type-safe APIs, and improved deprecation handling | Default on 26.04; requires Sury PPA on 24.04/22.04 |
| PHP 8.3 | Typed class constants, json_validate(), readonly property cloning | Security-only through December 2027 (active support ended) | WordPress 6.x, Laravel 11, Drupal 10 sites needing stable features with long security support | Default on 24.04; security patches only on Sury PPA |
| PHP 8.2 | Readonly classes, DNF types, null/false standalone types | Security-only through December 2026 (active support ended) | Legacy applications requiring PHP 8.2 compatibility, WordPress 6.1+ minimum requirements | No new features; security patches only |
Recommendation: Choose PHP 8.4 for new projects that benefit from property hooks for cleaner encapsulation, asymmetric visibility for immutable-style APIs, or the #[\Deprecated] attribute for better library maintenance. If your application already runs well on the distro default PHP and you prefer official Ubuntu security team maintenance, that version remains a solid choice.
This guide covers Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. Ubuntu 26.04 includes PHP 8.4 in the default repositories, so the PPA steps are optional. On Ubuntu 24.04 and 22.04, the Ondrej Sury PPA provides PHP 8.4 packages. Commands work identically across releases unless otherwise noted. For official PHP version support timelines, see the PHP supported versions page.
Explore PHP 8.4 Feature Highlights
PHP 8.4 provides tangible benefits for specific development scenarios. Property hooks allow you to define get and set logic directly within property declarations, eliminating verbose getter/setter methods while maintaining encapsulation. Asymmetric visibility lets you declare properties as publicly readable but privately writable using syntax like public private(set).
The #[\Deprecated] attribute marks functions or methods as deprecated with custom messages and version information, replacing docblock comments with enforceable runtime warnings. The updated DOM API now includes \Dom\HTMLDocument and \Dom\XMLDocument classes with proper HTML5 parsing support. New array utility functions like array_find(), array_find_key(), array_any(), and array_all() simplify common search patterns.
Beyond these headline features, PHP 8.4 introduces several quality-of-life improvements. You can now chain methods directly on new object instantiation without parentheses using new MyClass()->method() syntax. PDO gains driver-specific subclasses like Pdo\MySql and Pdo\Sqlite for better IDE autocompletion and type safety. New multibyte string functions mb_trim(), mb_ltrim(), and mb_rtrim() handle Unicode whitespace correctly. The BCMath extension adds an object-oriented API along with a new bcdivmod() function. Finally, cURL now supports HTTP/3 through CURL_HTTP_VERSION_3 and CURL_HTTP_VERSION_3ONLY constants. For a complete list of changes, see the official PHP 8.4 release announcement.
Add the PHP 8.4 PPA on Ubuntu 24.04 and 22.04
Update System Packages
Before adding external repositories, synchronize your package index and upgrade installed packages to ensure compatibility:
sudo apt update
sudo apt upgrade
Install Prerequisites for PPA Management
The software-properties-common package provides the add-apt-repository command needed to add PPAs. Install it along with other common utilities:
sudo apt install software-properties-common ca-certificates lsb-release -y
The
apt-transport-httpspackage is no longer needed on Ubuntu 22.04 and newer. HTTPS support is now built into APT directly, so you can skip any guides that still list it as a prerequisite.
Add the Ondrej Sury PHP PPA
If you are using Ubuntu 26.04 LTS, skip this entire PPA section. PHP 8.4 is included in Ubuntu 26.04’s default repositories, so you can install it directly with
sudo apt install php8.4without adding a PPA.
The Ondrej Sury PPA provides co-installable PHP versions from 5.6 through 8.5, allowing you to run multiple PHP versions side by side. Add the repository:
sudo add-apt-repository ppa:ondrej/php -y
After adding the PPA, refresh the package index to make the new packages available:
sudo apt update
Confirm PHP 8.4 is available from the PPA:
apt-cache policy php8.4
Output from Ubuntu 24.04 confirming the Sury PPA as the package source:
php8.4:
Installed: (none)
Candidate: 8.4.16-1+ubuntu24.04.1+deb.sury.org+1
Version table:
8.4.16-1+ubuntu24.04.1+deb.sury.org+1 500
500 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble/main amd64 Packages
The version numbers and codename match your Ubuntu release. On Ubuntu 22.04, the output shows
jammyinstead ofnoble. Your output will display the current version available from the Sury PPA.
Install PHP 8.4 on Ubuntu
Select the installation method that matches your web server configuration. Apache users can choose between mod_php (simpler setup) or PHP-FPM (better resource management). Nginx requires PHP-FPM exclusively.
Compare PHP Installation Methods
| Method | Web Server | Process Model | Best For |
|---|---|---|---|
| Apache mod_php | Apache only | Embedded in worker | Development environments; simplest setup |
| Apache + PHP-FPM | Apache | Separate pool managers | Production sites; better memory management |
| Nginx + PHP-FPM | Nginx | Separate pool managers | High-traffic production; static file performance |
Use PHP-FPM for production environments because it runs as a separate process pool, allowing finer control over memory usage, timeouts, and process lifecycle. Reserve mod_php for development or low-traffic sites where simplicity matters more than resource efficiency.
Option 1: Install PHP 8.4 with Apache mod_php
The mod_php approach loads PHP as an Apache module, making it suitable for development environments or smaller sites where simplicity matters more than process isolation. Install the packages:
sudo apt install php8.4 libapache2-mod-php8.4
Restart Apache to activate the PHP module:
sudo systemctl restart apache2
Verify PHP loads correctly:
php --version
Expected output on Ubuntu 24.04/22.04 (Sury PPA):
PHP 8.4.16 (cli) (built: Dec 18 2025 23:38:53) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.16, Copyright (c) Zend Technologies
with Zend OPcache v8.4.16, Copyright (c), by Zend Technologies
Expected output on Ubuntu 26.04 (default repositories):
PHP 8.4.11 (cli) (built: Aug 13 2025 01:43:48) (NTS)
Copyright (c) The PHP Group
Built by Ubuntu
Zend Engine v4.4.11, Copyright (c) Zend Technologies
with Zend OPcache v8.4.11, Copyright (c), by Zend Technologies
Option 2: Install PHP 8.4 with Apache and PHP-FPM
PHP-FPM runs PHP in a separate process pool, providing better memory management and the ability to run different PHP versions for different virtual hosts. Install the required packages:
sudo apt install php8.4-fpm libapache2-mod-fcgid
If you previously installed mod_php, disable it before enabling PHP-FPM:
sudo a2dismod php8.4
Enable the required Apache modules and PHP-FPM configuration:
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.4-fpm
Enable and start PHP-FPM, then restart Apache to apply changes:
sudo systemctl enable php8.4-fpm --now
sudo systemctl restart apache2
Confirm PHP-FPM is running:
sudo systemctl status php8.4-fpm
Expected output confirming active status:
● php8.4-fpm.service - The PHP 8.4 FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php8.4-fpm.service; enabled; preset: enabled)
Active: active (running) since [date and time]
Main PID: [pid] (php-fpm8.4)
Tasks: [number]
Memory: [size]
CPU: [time]
CGroup: /system.slice/php8.4-fpm.service
Option 3: Install PHP 8.4 with Nginx and PHP-FPM
Nginx processes PHP through FastCGI, making PHP-FPM the only option. Install the required packages:
sudo apt install php8.4 php8.4-fpm php8.4-cli
Enable and start PHP-FPM:
sudo systemctl enable php8.4-fpm --now
Verify PHP-FPM status:
sudo systemctl status php8.4-fpm
If running correctly, you should see output confirming active status:
● php8.4-fpm.service - The PHP 8.4 FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php8.4-fpm.service; enabled; preset: enabled)
Active: active (running) since [date and time]
Configure Nginx Server Block for PHP-FPM
Add this location block to your Nginx server configuration to route PHP requests through PHP-FPM 8.4:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
}
Before applying changes, test the configuration syntax:
sudo nginx -t
Valid configuration produces this output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Once validated, apply the configuration:
sudo systemctl restart nginx
Verify PHP 8.4 Installation
Regardless of which method you chose, confirm PHP 8.4 installed correctly:
php --version
Expected output (version varies by Ubuntu release and package source):
PHP 8.4.16 (cli) (built: Dec 18 2025 23:38:53) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.16, Copyright (c) Zend Technologies
with Zend OPcache v8.4.16, Copyright (c), by Zend Technologies
Install PHP 8.4 Extensions on Ubuntu
Install Common PHP 8.4 Extensions
Most web applications require extensions beyond the base PHP installation. Install a comprehensive set covering WordPress, Laravel, and general PHP development needs:
sudo apt install php8.4-{curl,mysql,gd,opcache,zip,intl,common,bcmath,imagick,readline,memcached,redis,mbstring,apcu,xml,soap}
JSON support is built into PHP 8.0 and later, so no separate
php8.4-jsonpackage exists. Thephp8.4-xmlpackage provides DOM, SimpleXML, XMLReader, and XMLWriter support. Thephp8.4-mysqlpackage includes both MySQLi and MySQLnd drivers.
After installation, restart your PHP handler to load the new extensions. For PHP-FPM users:
sudo systemctl restart php8.4-fpm
If you installed PHP 8.4 with Apache mod_php instead of PHP-FPM, restart Apache to load the new extensions:
sudo systemctl restart apache2
Verify that PHP loads the core extensions:
php8.4 -m | grep -E 'curl|mysqli|gd|mbstring|xml'
Expected output showing the extensions are active:
curl gd libxml mbstring mysqli xml xmlreader xmlwriter
PHP 8.4 Extension Reference
For reference, the extensions above provide these capabilities:
- php-curl: HTTP client for API requests and remote file operations.
- php-mysql: MariaDB and MySQL database connectivity via MySQLi and MySQLnd.
- php-gd: Image creation and manipulation (thumbnails, watermarks, captchas).
- php-opcache: Bytecode caching to reduce PHP compilation overhead.
- php-zip: ZIP archive creation and extraction.
- php-intl: Internationalization including number formatting, date handling, and collation.
- php-bcmath: Arbitrary precision mathematics for financial calculations.
- php-imagick: Advanced image processing through ImageMagick.
- php-memcached and php-redis: Distributed caching backends for session storage and object caching.
- php-mbstring: Multibyte string handling for UTF-8 and international text processing.
- php-apcu: In-memory user data cache for frequently accessed application data.
- php-xml: XML parsing including DOM, SimpleXML, and XSL support.
- php-soap: SOAP web services client and server functionality.
Search Available PHP 8.4 Extensions
To explore additional options, first list all available PHP 8.4 modules from the repository:
apt search php8.4-
Sample output showing available extensions:
Sorting... Full Text Search... php8.4-amqp/noble 2.x.x amd64 AMQP extension for PHP php8.4-apcu/noble 5.x.x amd64 APC User Cache for PHP php8.4-bcmath/noble 8.4.x amd64 Bcmath module for PHP [additional packages...]
List Loaded PHP 8.4 Modules
Alternatively, display all currently active PHP modules:
php8.4 -m
Sample output showing loaded modules:
[PHP Modules] calendar Core ctype curl date dom exif fileinfo filter gd hash iconv intl json libxml mbstring mysqli openssl pcre PDO pdo_mysql Phar readline Reflection session SimpleXML sockets sodium SPL standard tokenizer xml Zend OPcache zip zlib [Zend Modules] Zend OPcache
Install PHP 8.4 Development Tools
For code coverage analysis and extension development, install these packages:
sudo apt install php8.4-xdebug php8.4-pcov php8.4-dev
The
php8.4-xdebugextension significantly impacts performance. Install it only on development systems, not production servers. For production-safe code coverage, usephp8.4-pcovinstead.
The php8.4-pcov package provides lightweight code coverage reporting compatible with PHPUnit, while php8.4-dev includes headers and tools for compiling PHP extensions from source.
Configure PHP 8.4 Settings
Locate PHP Configuration Files
PHP 8.4 maintains separate configuration files for CLI (command line) and PHP-FPM (web server). To find the active configuration file for each environment, run:
php8.4 --ini | head -3
This command produces output showing CLI configuration paths:
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 PHP-FPM (used by Apache with PHP-FPM or Nginx), the configuration file is at /etc/php/8.4/fpm/php.ini instead. Changes to CLI settings do not affect web applications, and vice versa.
Adjust Common PHP Settings
To modify settings for web applications using PHP-FPM, edit the FPM configuration file:
sudo nano /etc/php/8.4/fpm/php.ini
Common settings to adjust based on your application requirements:
; Maximum upload file size (default: 2M)
upload_max_filesize = 64M
; Maximum POST data size (must be >= upload_max_filesize)
post_max_size = 64M
; Maximum memory per script (default: 128M)
memory_limit = 256M
; Maximum script execution time in seconds (default: 30)
max_execution_time = 120
; Maximum input variables (default: 1000)
max_input_vars = 3000
For production servers, also consider setting
display_errors = Offto prevent exposing sensitive information,expose_php = Offto hide the PHP version in HTTP headers, and enabling OPcache with appropriate settings for your workload.
After making changes, restart PHP-FPM to apply them:
sudo systemctl restart php8.4-fpm
Verify the CLI reflects the new settings:
php8.4 -i | grep upload_max_filesize
This confirms the new value took effect:
upload_max_filesize => 64M => 64M
The
php8.4 -icommand shows CLI settings from/etc/php/8.4/cli/php.ini. To verify web application settings, create aphpinfo()test page or check/etc/php/8.4/fpm/php.inidirectly. Changes to one configuration file do not affect the other.
Run Multiple PHP Versions on Ubuntu
How Multiple PHP Versions Work Together
The Sury PPA packages each PHP version independently, so installing PHP 8.4 does not remove existing PHP installations. You can run PHP 8.3, 8.4, and other versions simultaneously, assigning different versions to different virtual hosts or projects.
Switch Command Line PHP Version
To manage CLI versions, use update-alternatives to configure which PHP version responds to the php command:
sudo update-alternatives --config php
You will then see interactive output showing available versions:
There are 3 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/php8.4 84 auto mode 1 /usr/bin/php8.3 83 manual mode 2 /usr/bin/php8.4 84 manual mode Press <enter> to keep the current choice[*], or type selection number:
Enter the number corresponding to your preferred version. Alternatively, to set PHP 8.4 directly without the interactive prompt:
sudo update-alternatives --set php /usr/bin/php8.4
Switch Apache PHP Version
When using mod_php with Apache, disable the current PHP module and enable the desired version:
sudo a2dismod php8.3
sudo a2enmod php8.4
sudo systemctl restart apache2
Switch Apache PHP-FPM Version
For Apache with PHP-FPM, instead swap the configuration files:
sudo a2disconf php8.3-fpm
sudo a2enconf php8.4-fpm
sudo systemctl restart apache2
Switch Nginx PHP-FPM Version
For Nginx, update the fastcgi_pass directive in your server block to point to the desired PHP-FPM socket:
# For PHP 8.3
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
# For PHP 8.4
fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
After making changes, test and reload Nginx:
sudo nginx -t && sudo systemctl reload nginx
Remove PHP 8.4 from Ubuntu
Uninstall PHP 8.4 Packages
If you no longer need PHP 8.4, remove it and its extensions while preserving other PHP versions by running:
sudo apt remove php8.4*
APT will display the packages to be removed before proceeding:
The following packages will be removed: libapache2-mod-php8.4 php8.4 php8.4-cli php8.4-common php8.4-curl php8.4-fpm php8.4-gd php8.4-mbstring php8.4-mysql php8.4-opcache php8.4-xml php8.4-zip [additional packages...]
Alternatively, to remove configuration files as well, use purge instead of remove:
The
purgecommand permanently deletes PHP configuration files in/etc/php/8.4/. If you have customizedphp.inior pool configurations, back them up first withsudo cp -r /etc/php/8.4 ~/php84-backup.
sudo apt purge php8.4*
Finally, clean up any orphaned dependencies that were installed only for PHP 8.4:
sudo apt autoremove
Remove the Ondrej Sury PPA
If you installed PHP 8.4 from Ubuntu 26.04’s default repositories (without adding the Sury PPA), skip this PPA removal step.
If you added the Sury PPA and no longer need packages from it, remove the configuration:
sudo add-apt-repository --remove ppa:ondrej/php -y
sudo apt update
After removing the PPA, verify PHP 8.4 is no longer available:
apt-cache policy php8.4
Expected output showing no installation candidate:
php8.4: Installed: (none) Candidate: (none) Version table:
Troubleshoot PHP 8.4 Installation Issues
PHP-FPM Socket Not Found
If Nginx returns a 502 Bad Gateway error, first check the Nginx error log for socket connection failures:
sudo tail -5 /var/log/nginx/error.log
A common error indicating PHP-FPM is not running looks like this:
connect() to unix:/var/run/php/php8.4-fpm.sock failed (2: No such file or directory) while connecting to upstream
Verify the PHP-FPM socket exists:
ls -la /var/run/php/php8.4-fpm.sock
If the socket exists, the output looks like this:
srw-rw---- 1 www-data www-data 0 [date] [time] /var/run/php/php8.4-fpm.sock
Conversely, if the socket is missing, check PHP-FPM status and then start the service:
sudo systemctl status php8.4-fpm
sudo systemctl enable php8.4-fpm --now
Verify the socket now exists and test the configuration:
ls -la /var/run/php/php8.4-fpm.sock
sudo nginx -t && sudo systemctl reload nginx
Wrong PHP Version Active
Occasionally, if php --version shows an older PHP version after installing 8.4, you need to update the alternatives system:
sudo update-alternatives --set php /usr/bin/php8.4
Verify the change took effect:
php --version
Expected output confirming PHP 8.4 is now the default:
PHP 8.4.16 (cli) (built: Dec 18 2025 23:38:53) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.16, Copyright (c) Zend Technologies
with Zend OPcache v8.4.16, Copyright (c), by Zend Technologies
Extension Not Loading After Installation
If an extension appears installed but does not load, first confirm APT installed the package:
dpkg -l | grep php8.4-curl
Expected output confirming the package exists:
ii php8.4-curl 8.4.16-1+ubuntu24.04.1+deb.sury.org+1 amd64 CURL module for PHP
Then check if the extension is enabled in the PHP configuration:
php8.4 -m | grep curl
However, if APT installed the extension but PHP does not show it, restart the PHP handler:
# For PHP-FPM
sudo systemctl restart php8.4-fpm
# For Apache mod_php
sudo systemctl restart apache2
Update PHP 8.4 on Ubuntu
On Ubuntu 24.04 and 22.04, PHP 8.4 receives updates through the Sury PPA. On Ubuntu 26.04, updates come from Ubuntu’s official repositories. To update to the latest point release while keeping other system packages unchanged:
sudo apt update
sudo apt install --only-upgrade php8.4*
This command updates all PHP 8.4 packages (CLI, FPM, extensions) without upgrading unrelated system packages. After updating, restart PHP-FPM to apply changes:
sudo systemctl restart php8.4-fpm
Verify the new version:
php8.4 --version
Conclusion
You now have PHP 8.4 configured with property hooks, asymmetric visibility, and the #[\Deprecated] attribute on your Ubuntu system. Consider setting up phpMyAdmin for database administration, configuring Nginx FastCGI caching for better performance, or deploying WordPress with Nginx and MariaDB.
Useful Links
For additional resources and documentation:
- PHP Official Website: Visit the official PHP website for information about the programming language, its features, and download options.
- PHP 8.4 Release Notes: Explore the release notes for PHP 8.4 to learn about new features, improvements, and changes.
- PHP 8.4 ChangeLog: Review the changelog for PHP 8 to see the detailed list of changes and updates in each release.
- PHP Documentation: Access comprehensive documentation for detailed guides on using and programming with PHP.
- PHP Supported Versions: Check current PHP version support status and end-of-life dates.
- deb.sury.org: Official source for the Ondrej Sury PHP PPA with packages for Ubuntu and Debian.