- Posted on
- • Linux
How to Install PHP 8.3 on Ubuntu and Debian
- Author
-
-
- User
- edan
- Posts by this author
- Posts by this author
-

PHP 8.3 marks a significant advancement in the PHP ecosystem, introducing features such as typed class constants, a new set of exceptions for the DateTime extension, the json_validate
function, and various other enhancements, changes, and deprecations.
This guide details the steps needed to install or upgrade to PHP 8.3 on Ubuntu (versions 20.04, 22.04, and 24.04) and Debian (versions 10, 11, and 12). It also provides insights into integrating popular PECL extensions and configuring PHP for different web servers.
Quick Installation Steps
For those who prefer a fast approach to install PHP 8.3, commands for both Debian and Ubuntu are provided below.
Debian (10, 11, and 12)
# Save existing PHP package list to a file for reference
sudo dpkg -l | grep php | tee packages.txt
# Install required package for HTTPS support if not already present
sudo apt install apt-transport-https
# Add the repository for PHP packages and import the signing key
sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
# Update the package list
sudo apt update
# Install the desired PHP 8.3 packages
sudo apt install php8.3 php8.3-cli php8.3-{bz2,curl,mbstring,intl}
# Choose between FPM or Apache module
sudo apt install php8.3-fpm # for FPM
# OR
# sudo apt install libapache2-mod-php8.3 # for Apache
# Enable the new PHP 8.3 configuration for Apache if applicable
sudo a2enconf php8.3-fpm
# Disable the older version configuration if upgrading
sudo a2disconf php8.2-fpm
# Remove old PHP versions if necessary
sudo apt purge php8.2*
Ubuntu (20.04, 22.04, 24.04)
# Save existing PHP package list to a file for reference
sudo dpkg -l | grep php | tee packages.txt
# Add Ondřej’s PPA for PHP
sudo add-apt-repository ppa:ondrej/php
sudo apt update
# Install the desired PHP 8.3 packages
sudo apt install php8.3 php8.3-cli php8.3-{bz2,curl,mbstring,intl}
# Choose between FPM or Apache module
sudo apt install php8.3-fpm # for FPM
# OR
# sudo apt install libapache2-mod-php8.3 # for Apache
# Enable the new PHP 8.3 configuration for Apache if applicable
sudo a2enconf php8.3-fpm
# Disable the older version configuration if upgrading
sudo a2disconf php8.2-fpm
# Remove old PHP versions if necessary
sudo apt purge php8.2*
Detailed Installation Steps
Prerequisites
Both Debian and Ubuntu currently do not include PHP 8.3 in their default repositories. The packages utilized here are sourced from Ondřej Surý’s repository. This guide caters to users on different Debian and Ubuntu versions mentioned earlier.
Check Current PHP Packages
Before initiating an upgrade, it’s beneficial to list current PHP packages. This step is not required for fresh installations:
dpkg -l | grep php | tee packages.txt
Add the PHP Repository
To access PHP 8.3, add Ondřej Surý’s repository for PHP. The following commands facilitate this addition for both Debian and Ubuntu.
For Debian:
sudo apt install apt-transport-https
sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
For Ubuntu:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Install PHP 8.3
With the repository added, initiate the installation of PHP 8.3.
sudo apt install php8.3-common php8.3-cli php8.3-fpm php8.3-{curl,bz2,mbstring,intl}
Key Extensions
- The
php8.3-common
package installs several PHP extensions. Individual extensions can also be installed selectively. php8.3-fpm
is essential for integrating PHP with web servers using FastCGI.
Installing Additional PHP Extensions
A number of popular PECL extensions can also be installed from the repository. Here are some commonly used extensions:
Extension Name | Package Name |
---|---|
Xdebug | php8.3-xdebug |
Redis | php8.3-redis |
PCov | php8.3-pcov |
Image Magick | php8.3-imagick |
APCu | php8.3-apcu |
To check for available PHP extensions, use the following command:
sudo apt search php8.3-<extension-name>
Configure Web Server Integration
Proper integration of PHP with your web server is critical. Depending on your setup, you may need to configure either Apache or Nginx.
For Apache:
If using PHP-FPM, enable it with the following commands:
sudo a2enconf php8.3-fpm
sudo a2disconf php8.2-fpm # If upgrading
sudo systemctl restart apache2
If instead, PHP is needed as an Apache module, install and enable it with:
sudo apt install libapache2-mod-php8.3
sudo a2enmod php8.3
sudo a2dismod php8.2 # If upgrading
sudo systemctl restart apache2
For Nginx:
Update your Nginx configuration to use the PHP-FPM socket:
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
Test the PHP Installation
After installation, confirm that PHP 8.3 is properly set up:
php -v
You should see output indicating the current PHP version.
Migrate Configuration Files
If upgrading from an older version, be sure to migrate your PHP configuration files carefully. Instead of copying INI files directly, make adjustments as necessary based on the new version’s standards.
Remove Older PHP Versions
To maintain a clean environment after upgrading, you can remove outdated PHP packages as needed:
sudo apt purge php8.2*
Running PHP 8.3 Alongside Other Versions
Multiple PHP versions can coexist on the same server. The PHP binary for each version is accessible directly via specified paths such as /usr/bin/php8.3
for version 8.3. Adjust the default PHP CLI using update-alternatives
:
sudo update-alternatives --config php
Conclusion
Installing or upgrading to PHP 8.3 on Ubuntu and Debian is a straightforward process, providing access to exciting new features and improvements. Following this guide ensures a smooth transition or installation, helping developers take full advantage of the latest advancements in the PHP ecosystem. Whether setting up a new server or upgrading an existing one, leveraging PHP 8.3 will enhance your web applications and development capabilities.