Notes on adding more php support to Ubuntu Server

Make sure you run an apt update && apt upgrade before adding this repo.

Reboot as necessary.


Adding the repo

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

Check the contents of /etc/apt/sources.list.d/ondrej.list and make sure the distro name is proper. Ie Ubuntu 22.04 should have jammy in the mentioned repo file.


Upgrade Php 8.1 to 8.2

$ sudo apt install php8.2


Don't forget to add any missing php modules to php 8.2, that are available in php 8.1 for your use case!


Switch the php versions

Check current (active) php version and then switch them.

$ php -v$ sudo update-alternatives --config php

Choose either 0 for auto mode or eg 1 for a php version that won't get changed at the next upgrade. In this case choose 2 and press enter.


root@server:~# update-alternatives --config php
There are 2 choices for the alternative php (providing /usr/bin/php).

Selection Path Priority Status
0 /usr/bin/php8.2 82 auto mode
* 1 /usr/bin/php8.1 81 manual mode
2 /usr/bin/php8.2 82 manual mode

Press <enter> to keep the current choice[*], or type selection number:

Now run php -v again to check that the correct php version is active.

root@server:~# php -v
PHP 8.2.13 (cli) (built: Nov 24 2023 08:47:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.13, Copyright (c) Zend Technologies
with Zend OPcache v8.2.13, Copyright (c), by Zend Technologies

Finally, check your web sites that they appear correctly with the new php version!


Apache2 php.ini settings

Default settings are usually okay, but I use these. Find the php.ini in /etc/php/8.2/apache2.


$ nano /etc/php/8.2/apache2/php.ini

memory_limit = 2048M
post_max_size = 160M
upload_max_filesize = 160M
max_execution_time = 60


Don't forget to save your php.ini!


And with that, we're done.















Stop Spam Harvesters, Join Project Honey Pot


Get a free SSL certificate!


The leading nonprofit defending digital privacy, free speech, and innovation.


The Linux Foundation provides a neutral, trusted hub for developers and organizations to code, manage, and scale open technology projects and ecosystems.


Kubuntu is an operating system built by a worldwide community of developers, testers, supporters and translators.


 43ef5c89 CanonicalUbuntudarktext