I have a newish server running Ubuntu 22.04, and I wanted to install a PHP 8.3 on it. It had PHP 8.1 running which is end-of-life with only Security Support Until 31 Dec 2025
Check your PHP version
Check what version of PHP you are currently running with
php -v
In my case
$ php -v
PHP 8.1.2-1ubuntu2.19 (cli) (built: Sep 30 2024 16:25:25) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2-1ubuntu2.19, Copyright (c), by Zend Technologies
I also have an Ubuntu 20.04 server that only has PHP 7.4 which is end-of-life.
$ php -v
PHP 7.4.3-4ubuntu2.24 (cli) (built: Sep 30 2024 18:16:20) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3-4ubuntu2.24, Copyright (c), by Zend Technologies
That PHP 7.4 should have been upgraded 2 years ago.
Prepare to upgrade to PHP 8.3
Add Ondřej Surý’s PHP PPA to the server. This repository has been exceptional and helpful for years and provides the latest PHP versions which Ubuntu’s repositories do not offer.
sudo add-apt-repository ppa:ondrej/php
Update the package cache so it learns about the new repository.
sudo apt update
Upgrade any packages that need it. Do this before installing any new packages.
sudo apt upgrade
Install PHP 8.3
Old way: Install PHP 8.3 as an Apache Module
One server had it installed as an Apache module. Here is how to update it. But PHP-FPM is better.
sudo apt install php8.3 libapache2-mod-php8.3
Restart Apache
sudo systemctl restart apache2
Install Apache with PHP-FPM
The other server had PHP-FPM installed
sudo apt install php8.3-fpm libapache2-mod-fcgid
Enable it
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.3-fpm
Restart Apache
sudo systemctl restart apache2
Check PHP version
Check your installation went okay. This is the verbose form of the command to report version.
php --version
In my case I have to configure the virtual server to use the newly installed version of PHP.
Install PHP extensions
I sometimes use image magick (imagick) and other extensions.
Get a list of currently installed PHP extensions
php -m
Customise this command with the extensions you want or need. Of course you can install all of them if you want.
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}
Test that everything is working as it should.