PHP 8.3 introduces typed class constants for stricter compile-time checks, the json_validate() function for efficient JSON validation without decoding, and deep-cloning support for readonly properties in __clone methods. These additions reduce boilerplate code and improve type safety in object-oriented applications. On Ubuntu, PHP 8.3 is available through Ondrej Sury’s PHP PPA, which provides co-installable PHP versions with regular security updates.
The steps below walk through adding the Sury PPA, installing PHP 8.3 with Apache or Nginx, configuring PHP-FPM for production workloads, and managing extensions. After completing these steps, you will have PHP 8.3 configured and ready to power WordPress, Laravel, or any application that benefits from typed constants and the improved JSON validation.
Select a PHP Version for Your Ubuntu System
Choose Between PHP 8.5, 8.3, 8.2, and Distro Default
Ubuntu repositories and the Sury PPA provide different PHP versions targeting distinct use cases. Consequently, 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.1 on 22.04, 8.3 on 24.04) |
| PHP 8.5 | URI extension, pipe operator, clone with properties | Active support through December 2026; security through December 2028 | Modern applications using functional programming patterns, URL parsing, and immutable object patterns | Requires Sury PPA; community-maintained updates |
| PHP 8.3 | Typed class constants, json_validate(), readonly property cloning | Active support through December 2025; security through December 2027 | WordPress 6.x, Laravel 11, Drupal 10 sites needing stable features with long security support | Requires Sury PPA on 22.04; community-maintained updates |
| PHP 8.2 | Readonly classes, DNF types, standalone null/false/true types | Security-only through December 2026 | Projects using readonly patterns, applications with strict typing requirements | Active support ended December 2024; requires Sury PPA |
Recommendation: Choose PHP 8.3 for production projects prioritizing proven stability and broad framework compatibility with WordPress 6.x, Laravel 11, and Drupal 10. While PHP 8.5 offers newer features like the pipe operator, PHP 8.3 provides a more established codebase with extensive community testing. Ubuntu 24.04 includes PHP 8.3 in its default repositories, though the Sury PPA provides faster point-release updates. For Ubuntu 22.04, the PPA is required since the default version is PHP 8.1. 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 22.04 LTS and 24.04 LTS installations. The Ondrej Sury PPA provides PHP 8.3 packages for these LTS releases. At the time of writing, the PPA does not yet publish packages for Ubuntu 26.04 LTS (resolute), so 26.04 users should use the default PHP 8.4 packages or wait for PPA support. Commands shown work identically on both 22.04 and 24.04 unless otherwise noted.
Explore PHP 8.3 Feature Highlights
PHP 8.3 provides tangible benefits for specific development scenarios. First, typed class constants allow you to declare explicit types on constants, enabling the compiler to catch type mismatches during static analysis rather than at runtime. Additionally, the new #[\Override] attribute ensures methods genuinely override parent methods, preventing silent bugs when parent signatures change.
Furthermore, the json_validate() function validates JSON strings without fully decoding them, improving performance when you only need to verify structure. The deep-cloning of readonly properties in __clone methods enables more flexible immutable object patterns. For a complete list of changes, see the official PHP 8.3 release announcement.
Add the PHP 8.3 PPA on Ubuntu
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
Next, 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
The Ondrej Sury PPA provides co-installable PHP versions from 5.6 through 8.3, allowing you to run multiple PHP versions side by side. Add the repository with:
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
Then, confirm PHP 8.3 is available from the PPA:
apt-cache policy php8.3
Expected output showing the Sury PPA as the package source:
php8.3:
Installed: (none)
Candidate: 8.3.x-1+ubuntu24.04.1+deb.sury.org+1
Version table:
8.3.x-1+ubuntu24.04.1+deb.sury.org+1 500
500 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble/main amd64 Packages
8.3.6-0ubuntu0.24.04.5 500
500 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages
The version numbers and codename will match your Ubuntu release. Replace
noblewithjammyfor Ubuntu 22.04. On Ubuntu 24.04, you will see both the PPA version and the default Ubuntu repository version; the PPA version typically has a higher version number. Your output will show the current version available from the Sury PPA.
Install PHP 8.3 on Ubuntu
At this point, 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). In contrast, 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 |
For production environments, PHP-FPM is recommended because it runs as a separate process pool, allowing finer control over memory usage, timeouts, and process lifecycle. Therefore, use mod_php only for development or low-traffic sites where simplicity matters more than resource efficiency.
Option 1: Install PHP 8.3 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. To begin, install the packages:
sudo apt install php8.3 libapache2-mod-php8.3
Afterward, restart Apache to activate the PHP module:
sudo systemctl restart apache2
Then, verify PHP is loaded:
php --version
You should see expected output similar to:
PHP 8.3.x (cli) (built: [date]) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.x, Copyright (c) Zend Technologies
with Zend OPcache v8.3.x, Copyright (c), by Zend Technologies
Option 2: Install PHP 8.3 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. To set this up, install the required packages:
sudo apt install php8.3-fpm libapache2-mod-fcgid
If mod_php is installed from a previous configuration, disable it before enabling PHP-FPM:
sudo a2dismod php8.3
Once installed, enable the required Apache modules and PHP-FPM configuration:
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.3-fpm
Now, enable and start PHP-FPM, then restart Apache to apply changes:
sudo systemctl enable php8.3-fpm --now
sudo systemctl restart apache2
Finally, confirm PHP-FPM is running:
sudo systemctl status php8.3-fpm
Expected output confirming active status:
● php8.3-fpm.service - The PHP 8.3 FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php8.3-fpm.service; enabled; preset: enabled)
Active: active (running) since [date and time]
Main PID: [pid] (php-fpm8.3)
Tasks: [number]
Memory: [size]
CPU: [time]
CGroup: /system.slice/php8.3-fpm.service
Option 3: Install PHP 8.3 with Nginx and PHP-FPM
Nginx processes PHP through FastCGI, making PHP-FPM the only option. Therefore, install the required packages:
sudo apt install php8.3 php8.3-fpm php8.3-cli
Next, enable and start PHP-FPM:
sudo systemctl enable php8.3-fpm --now
Then, verify PHP-FPM status:
sudo systemctl status php8.3-fpm
Expected output confirming active status:
● php8.3-fpm.service - The PHP 8.3 FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php8.3-fpm.service; enabled; preset: enabled)
Active: active (running) since [date and time]
Configure Nginx Server Block for PHP-FPM
Now, add this location block to your Nginx server configuration to route PHP requests through PHP-FPM 8.3:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
Before applying changes, test the configuration syntax:
sudo nginx -t
Expected output for valid configuration:
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.3 Installation
Regardless of which method you chose, confirm PHP 8.3 installed correctly:
php --version
You should see expected output similar to:
PHP 8.3.x (cli) (built: [date]) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.x, Copyright (c) Zend Technologies
with Zend OPcache v8.3.x, Copyright (c), by Zend Technologies
Install PHP 8.3 Extensions on Ubuntu
Install Common PHP 8.3 Extensions
Most web applications require extensions beyond the base PHP installation. Accordingly, install a comprehensive set covering WordPress, Laravel, and general PHP development needs:
sudo apt install php8.3-{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.3-jsonpackage exists. Thephp8.3-xmlpackage provides DOM, SimpleXML, XMLReader, and XMLWriter support. Thephp8.3-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.3-fpm
If you installed PHP 8.3 with Apache mod_php instead of PHP-FPM, restart Apache to load the new extensions:
sudo systemctl restart apache2
Subsequently, verify the core extensions are loaded:
php8.3 -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.3 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.3 Extensions
To explore additional options, you can list all available PHP 8.3 modules from the repository:
apt search php8.3-
Sample output showing available extensions:
Sorting... Full Text Search... php8.3-amqp/noble 2.x.x amd64 AMQP extension for PHP php8.3-apcu/noble 5.x.x amd64 APC User Cache for PHP php8.3-bcmath/noble 8.3.x amd64 Bcmath module for PHP [additional packages...]
List Loaded PHP 8.3 Modules
Alternatively, display all currently active PHP modules:
php8.3 -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.3 Development Tools
Additionally, for code coverage analysis and extension development, install these packages:
sudo apt install php8.3-xdebug php8.3-pcov php8.3-dev
The
php8.3-xdebugextension significantly impacts performance. Install it only on development systems, not production servers. For production-safe code coverage, usephp8.3-pcovinstead.
Specifically, the php8.3-pcov package provides lightweight code coverage reporting compatible with PHPUnit, while php8.3-dev includes headers and tools for compiling PHP extensions from source.
Configure PHP 8.3 Settings
Locate PHP Configuration Files
PHP 8.3 maintains separate configuration files for CLI (command line) and PHP-FPM (web server). Consequently, to find the active configuration file for each environment, run:
php8.3 --ini | head -3
Expected output showing CLI configuration paths:
Configuration File (php.ini) Path: /etc/php/8.3/cli Loaded Configuration File: /etc/php/8.3/cli/php.ini Scan for additional .ini files in: /etc/php/8.3/cli/conf.d
For PHP-FPM (used by Apache with PHP-FPM or Nginx), the configuration file is at /etc/php/8.3/fpm/php.ini instead. Notably, 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.3/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.3-fpm
Then verify the CLI reflects the new settings:
php8.3 -i | grep upload_max_filesize
Expected output confirming the new value:
upload_max_filesize => 64M => 64M
The
php8.3 -icommand shows CLI settings from/etc/php/8.3/cli/php.ini. To verify web application settings, create aphpinfo()test page or check/etc/php/8.3/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.3 does not remove existing PHP installations. As a result, you can run PHP 8.1, 8.2, and 8.3 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 2 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/php8.3 83 auto mode 1 /usr/bin/php8.2 82 manual mode 2 /usr/bin/php8.3 83 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.3 directly without the interactive prompt:
sudo update-alternatives --set php /usr/bin/php8.3
Switch Apache PHP Version
Similarly, when using mod_php with Apache, first disable the current PHP module and then enable the desired version:
sudo a2dismod php8.2
sudo a2enmod php8.3
sudo systemctl restart apache2
Switch Apache PHP-FPM Version
For Apache with PHP-FPM, instead swap the configuration files:
sudo a2disconf php8.2-fpm
sudo a2enconf php8.3-fpm
sudo systemctl restart apache2
Switch Nginx PHP-FPM Version
Likewise, for Nginx, update the fastcgi_pass directive in your server block to point to the desired PHP-FPM socket:
# For PHP 8.2
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
# For PHP 8.3
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
After making changes, test and reload Nginx:
sudo nginx -t && sudo systemctl reload nginx
Remove PHP 8.3 from Ubuntu
Uninstall PHP 8.3 Packages
To remove PHP 8.3 and its extensions while preserving other PHP versions, run:
sudo apt remove php8.3*
APT will then display the packages to be removed before proceeding:
The following packages will be removed: libapache2-mod-php8.3 php8.3 php8.3-cli php8.3-common php8.3-curl php8.3-fpm php8.3-gd php8.3-mbstring php8.3-mysql php8.3-opcache php8.3-xml php8.3-zip [additional packages...]
Alternatively, to remove configuration files as well, use purge instead of remove:
Warning: The
purgecommand permanently deletes PHP configuration files in/etc/php/8.3/. If you have customizedphp.inior pool configurations, back them up first.
sudo apt purge php8.3*
Finally, clean up any orphaned dependencies that were installed only for PHP 8.3:
sudo apt autoremove
Remove the Ondrej Sury PPA
If you no longer need packages from the Sury PPA, remove the configuration:
sudo add-apt-repository --remove ppa:ondrej/php -y
sudo apt update
After removing the PPA, verify PHP 8.3 is no longer available:
apt-cache policy php8.3
Expected output showing no installation candidate (on Ubuntu 22.04):
php8.3: Installed: (none) Candidate: (none) Version table:
On Ubuntu 24.04, PHP 8.3 remains available from the default repositories even after removing the PPA. The output will show the Ubuntu repository version instead of “(none)”.
Troubleshoot PHP 8.3 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.3-fpm.sock failed (2: No such file or directory) while connecting to upstream
Next, verify the PHP-FPM socket exists:
ls -la /var/run/php/php8.3-fpm.sock
Expected output when the socket exists:
srw-rw---- 1 www-data www-data 0 [date] [time] /var/run/php/php8.3-fpm.sock
Conversely, if the socket is missing, check PHP-FPM status and then start the service:
sudo systemctl status php8.3-fpm
sudo systemctl enable php8.3-fpm --now
Afterward, verify the socket now exists and test the configuration:
ls -la /var/run/php/php8.3-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.3, you need to update the alternatives system:
sudo update-alternatives --set php /usr/bin/php8.3
Subsequently, verify the change took effect:
php --version
Expected output confirming PHP 8.3 is now the default:
PHP 8.3.x (cli) (built: [date]) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.x, Copyright (c) Zend Technologies
Extension Not Loading After Installation
If an extension appears installed but is not loading, first confirm it is installed:
dpkg -l | grep php8.3-curl
Expected output showing the package is installed:
ii php8.3-curl 8.3.x-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.3 -m | grep curl
If the extension is installed but not appearing, restart the PHP handler:
# For PHP-FPM
sudo systemctl restart php8.3-fpm
# For Apache mod_php
sudo systemctl restart apache2
Update PHP 8.3 on Ubuntu
PHP 8.3 receives updates through the Sury PPA. Consequently, to update to the latest point release while keeping other system packages unchanged, run:
sudo apt update
sudo apt install --only-upgrade php8.3*
This command updates all PHP 8.3 packages (CLI, FPM, extensions) without upgrading unrelated system packages. After updating, restart PHP-FPM to apply changes:
sudo systemctl restart php8.3-fpm
Then, verify the new version:
php8.3 --version
Conclusion
You now have PHP 8.3 configured with typed class constants, json_validate(), and readonly property cloning on your Ubuntu system. Moving forward, 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.3 Release Notes: Explore the release notes for PHP 8.3 to learn about new features, improvements, and changes.
- PHP 8.3 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.