-

Installing Latest php on ubuntu

Because I wanted to use features from PHP 8.3 on Ubuntu 22.04 and PHP 8.3 was not available, I installed a precompiled binary

here is the steps I followed

#update
sudo apt update
#add andrej repo
sudo add-apt-repository ppa:ondrej/php
sudo apt install php8.3 php8.3-fpm php8.3-common php8.3-mysql php8.3-zip php8.3-gd php8.3-mbstring php8.3-curl php8.3-xml php8.3-bcmath php-pdo-*
#use dist-upgrade to upgrade any module
apt dist-upgrade

#depending on version/environment, you may end up with multiple php versions
#if it doesn't automatically upgrade the php module, do it manually
pushd /etc/mods-enabled
#move the old symbolic link to tmp
mv php8.1.conf php8.1.load /tmp
ln -s ../mods-available/php8.3.conf
ln -s ../modes-available/php8.3.load

#restart apache
systemctl restart apache2

at this point you should be able to check the version of your php with phpinfo();

if it is not working, I would make sure you restore the old link from tmp and restart apache