How to Install PHP 8.3 on Ubuntu 22.04 or 20.04

This guide will demonstrate how to install PHP 8.3 on 22.04 or 20.04 LTS releases utilizing the command-line terminal with a third-party PPA maintained by Ondřej Surý.

PHP 8.3 marks a significant leap forward in the evolution of this widely used server-side scripting language, known for its flexibility, simplicity, and speed. With the introduction of PHP 8.3, developers gain access to a suite of enhancements that streamline coding practices, bolster security, and improve performance. This version continues to refine the language, building on the foundation laid by PHP 8.2, and introduces innovative and practical features.

PHP 8.3 Highlights:

  • Typed class constants ensure stricter type checks, leading to more robust codebases.
  • Dynamic class constant fetch enhances code readability and maintainability.
  • The new #[\Override] attribute makes code more reliable by enforcing method overrides.
  • Deep-cloning of readonly properties in the __clone method, enabling more flexible object copying.
  • json_validate() function for efficient validation of JSON strings.
  • Randomizer::getBytesFromString() method offers a secure way to generate random strings.
  • New methods and functions such as DOMElement::getAttributeNames(), IntlCalendar::setDate(), and ldap_connect_wallet(), expand PHP’s functionality.

These updates enhance PHP’s capabilities and underscore its ongoing commitment to security, performance, and developer productivity. PHP 8.3 is poised to support the next generation of web applications with these features.

Let’s dive into the technical steps to embrace PHP 8.3’s potential.

Import PHP 8.3 PPA on Ubuntu

Update Ubuntu Before PHP 8.3 Installation

Before installing PHP, it’s essential to update your Ubuntu system. This ensures system security and compatibility for new software installations.

Begin by refreshing your package list and upgrading any outdated packages with these commands:

sudo apt update
sudo apt upgrade

Install Initial Packages for PHP PPA on Ubuntu

Prepare your system for PHP’s Personal Package Archive (PPA) by installing the necessary packages. These packages facilitate the secure handling of additional repositories, including certificate authentication and software property management.

Execute the following command:

sudo apt install ca-certificates apt-transport-https software-properties-common lsb-release -y

Add PHP 8.3 PPA on Ubuntu

To access the latest PHP versions, integrate Ondřej Surý’s PHP PPA into your Ubuntu system. This repository is more up-to-date than Ubuntu’s default PHP packages.

Import this repository using the following:

sudo add-apt-repository ppa:ondrej/php -y

After incorporating the PPA, it’s important to update your package cache to recognize this new source:

sudo apt update

Conclude by upgrading any packages that require updates:

sudo apt upgrade

Install PHP 8.3 on Ubuntu via APT and PHP 8.3 PPA

Option 1: Install PHP as an Apache Module

For Apache HTTP server setups, installing PHP as a module optimizes server functionality.

To install PHP 8.3 on Ubuntu as an Apache module, execute:

sudo apt install php8.3 libapache2-mod-php8.3

After installation, restart Apache to integrate the new PHP 8.3 module:

sudo systemctl restart apache2

Option 2: Install Apache with PHP-FPM on Ubuntu

PHP-FPM enhances performance for high-traffic websites. To install PHP 8.3 with PHP-FPM for Apache, use:

sudo apt install php8.3-fpm libapache2-mod-fcgid

Activate PHP-FPM with:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.3-fpm

Then, restart Apache to implement the changes:

sudo systemctl restart apache2

Option 3: Install PHP 8.3 Support for Nginx

Nginx utilizes PHP-FPM to process PHP files. Install PHP 8.3 and PHP-FPM on Ubuntu for Nginx using:

sudo apt install php8.3 php8.3-fpm php8.3-cli

If PHP-FPM 8.3 doesn’t start automatically, initiate it manually:

sudo systemctl enable php8.3-fpm --now

Configuring Nginx Server Block for PHP-FPM 8.3 on Ubuntu

Modify the Nginx server block to handle PHP files by adding:

location ~ .php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}

Validate your Nginx configuration syntax with:

sudo nginx -t

A successful validation displays:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart Nginx to apply your modifications:

sudo systemctl restart nginx

Verifying PHP 8.3 Installation via CLI

To confirm the PHP 8.3 version installed, use:

php --version

This command reveals the current PHP version, ensuring your installation or upgrade is successful.

Successful PHP 8.3 Installation Terminal Output on Ubuntu
Terminal screenshot showing successful PHP 8.3 installation

Install PHP 8.3 Extensions on Ubuntu

Install PHP 8.3 Extensions

Tailor PHP 8.3 to your project’s specific needs on Ubuntu 22.04 or 20.04 by selecting appropriate extensions. This customization enhances both performance and security.

Install your chosen extensions with the following command example:

sudo apt install php8.3-{cli,fpm,curl,mysqlnd,gd,opcache,zip,intl,common,bcmath,imagick,xmlrpc,readline,memcached,redis,mbstring,apcu,xml,dom,memcache}

Understanding PHP 8.3 Extensions

  • php-cli: Runs PHP scripts in the command line.
  • php-fpm: FastCGI Process Manager, optimizing request handling.
  • php-curl: Facilitates server communication.
  • php-mysqlnd: MySQL Native Driver for database interaction.
  • php-gd: Image manipulation library.
  • php-opcache: Caches precompiled script bytecode to boost PHP performance.
  • php-zip: Manages zip file operations.
  • php-intl: Supports international character sets.
  • php-common: Offers functionalities common to various PHP modules.
  • php-bcmath: Handles precise floating-point arithmetic.
  • php-imagick: Image processing with ImageMagick.
  • php-xmlrpc: Provides XML-RPC server and client functions.
  • php-readline: Facilitates interactive terminal input.
  • php-memcached & php-redis: Enhance performance through caching.
  • php-mbstring: Manages multibyte character encodings.
  • php-apcu: User caching for PHP application performance.
  • php-xml & php-dom: For XML parsing and manipulation.

To explore more modules, use the search command:

sudo apt search php8.3-
Terminal Search for PHP 8.3 Extensions on Ubuntu
Using the terminal to search for PHP 8.3 extensions

Monitoring Installed PHP 8.3 Modules

Regularly check and manage your PHP modules to ensure system efficiency. List the loaded PHP modules with:

php8.3 -m
Installed PHP 8.3 Extensions in Ubuntu Terminal
Terminal output of PHP 8.3 extensions installed on Ubuntu

Install PHP 8.3 Development Tools on Ubuntu

For advanced PHP development and debugging, install the following tools:

sudo apt install php8.3-pcov php8.3-dev

These steps guide you through optimizing your PHP 8.3 environment on Ubuntu, ensuring a balance between functionality and system performance.

Final Thoughts

In this guide, we’ve navigated through the key steps to install PHP 8.3 on Ubuntu 22.04 or 20.04, tailoring to different server setups like Apache and Nginx. As you move forward, remember to keep your system and PHP versions up-to-date for enhanced security and performance. You’re now equipped to fully utilize PHP 8.3’s capabilities in your web development endeavors, bringing more efficiency and robustness to your projects. Keep exploring and experimenting with PHP’s features to maximize your web development potential.

3 thoughts on “How to Install PHP 8.3 on Ubuntu 22.04 or 20.04”

  1. I’m getting an error with php8.3-xdebug. Specifically, “E: Couldn’t find any package by glob ‘php8.3-xdebug'”. Any one else having this same error?

    Reply
    • Looks like I might have overlooked that detail initially. You’re right, Xdebug version 3.3 is expected to support PHP 8.3, but it seems it hasn’t been released yet. Currently, Xdebug 3.3 is still in its alpha stage. With PHP 8.3 just out, I’m guessing Xdebug 3.3 will move to general release soon.

      Here are a couple of helpful links about it. Sorry for any confusion earlier with the command, I thought it was already available.

      https://xdebug.org/download
      https://xdebug.org/docs/compat

      Also, since PHP 8.3 has been released, the PHP PPA is quite active. If you’re using it, make sure to keep an eye out for updates, especially over the next week.

      Reply

Leave a Comment