How to Install PHP 8.3 on an EC2 Ubuntu 22.04 LTS Instance

3 min read

Ubuntu 22.04 ships with PHP 8.1 by default, which is already past its active support window. This guide shows you how to install PHP 8.3 on an EC2 Ubuntu 22.04 instance using the ondrej/php PPA, with configuration steps for both Apache and Nginx.

PHP 8.3 brings typed class constants, the json_validate() function, and several performance improvements over 8.1. If your application or CMS (like WordPress) recommends PHP 8.2+, this is the way to get there on Ubuntu 22.04.

Prerequisites

Add the ondrej/php PPA

The default Ubuntu 22.04 repositories only include PHP 8.1. To get PHP 8.3, add the ondrej/php PPA — the most widely used third-party PHP repository for Ubuntu.

sudo apt update
sudo apt install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
  • software-properties-common — provides the add-apt-repository command
  • add-apt-repository ppa:ondrej/php -y — adds the PPA and accepts the key automatically

Install PHP 8.3 and Common Extensions

Install PHP 8.3 along with the extensions most applications need.

sudo apt install -y php8.3 php8.3-cli php8.3-common php8.3-mbstring \
  php8.3-gd php8.3-intl php8.3-xml php8.3-mysql php8.3-zip \
  php8.3-curl php8.3-tidy php8.3-imagick php8.3-opcache php8.3-bcmath php8.3-readline

Here is what each extension does:

Extension Purpose
cli Run PHP scripts from the command line
common Shared files (includes tokenizer, fileinfo, PDO, etc.)
mbstring Multibyte string handling (required by most frameworks)
gd Image processing
intl Internationalization functions
xml XML parsing (includes DOM, SimpleXML)
mysql MySQL/MariaDB database driver
zip ZIP archive support
curl HTTP client for API requests
tidy HTML cleanup and repair
imagick ImageMagick bindings for advanced image processing
opcache Bytecode caching for better performance
bcmath Arbitrary precision math
readline Interactive shell support

You don’t need a separate php8.3-json package — JSON support has been built into PHP core since version 8.0.

Configure PHP 8.3 with Apache

If you’re running Apache, install the PHP module and enable it.

sudo apt install -y libapache2-mod-php8.3
sudo a2enmod php8.3
sudo systemctl restart apache2
  • libapache2-mod-php8.3 — the Apache module that processes PHP files
  • a2enmod php8.3 — enables the module in Apache’s configuration

If you had a previous PHP version enabled (like 8.1), disable it first:

sudo a2dismod php8.1
sudo a2enmod php8.3
sudo systemctl restart apache2

Configure PHP 8.3 with Nginx

Nginx doesn’t process PHP directly — it passes requests to PHP-FPM (FastCGI Process Manager). Install it:

sudo apt install -y php8.3-fpm
sudo systemctl enable php8.3-fpm
sudo systemctl start php8.3-fpm

Then update your Nginx server block to forward .php requests to the PHP-FPM socket. Add this inside your server {} block:

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

Test the config and reload Nginx:

sudo nginx -t
sudo systemctl reload nginx
  • nginx -t — validates the configuration file syntax before reloading
  • The FPM socket path /run/php/php8.3-fpm.sock must match the version you installed

Set PHP 8.3 as the Default CLI Version

If you have multiple PHP versions installed, set 8.3 as the default for CLI use:

sudo update-alternatives --set php /usr/bin/php8.3

Verify the Installation

Confirm PHP 8.3 is installed and active:

php -v

You should see output like:

PHP 8.3.30 (cli) (built: Jan 18 2026 14:22:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.30, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.30, Copyright (c), by Zend Technologies

To see all loaded modules:

php -m

What About PHP 8.4 or 8.5?

The ondrej/php PPA also provides PHP 8.4 and 8.5. If you want a newer version, replace 8.3 with 8.4 or 8.5 in all the commands above. PHP 8.3 continues to receive security updates and is a solid choice for production if your application or hosting stack requires it.

Conclusion

You now have PHP 8.3 running on your EC2 Ubuntu 22.04 instance with either Apache or Nginx. The ondrej/php PPA makes it straightforward to install and manage PHP versions that aren’t in Ubuntu’s default repositories.

Next, you might want to install MySQL to complete your LAMP/LEMP stack, or set up WordPress on your new PHP installation.