Update
Add
repo ondrej
sudo apt-get update
sudo apt -y install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/apache2
sudo apt-get update
Install
sudo apt update
sudo apt -y install php7.4
php -v
php.ini
sudo gedit /etc/php/7.4/apache2/php.ini
sudo diff -y -W 120 --suppress-common-lines
/etc/php/7.2/apache2/php.ini
/etc/php/7.4/apache2/php.ini
Install some commonly used
extensions
sudo apt install php7.4-common
sudo apt install php7.4-mysql
sudo apt install php-curl
Enable PHP
sudo a2dismod php7.2
sudo a2enmod php7.4
Restart apache
systemctl restart apache2
Switch
Switch between php versions.
sudo a2dismod php8.0
sudo a2enmod php8.3
systemctl restart apache2
CLI default
To set PHP 8.3 as the default version in the CLI use:
sudo update-alternatives --set php /usr/bin/php8.3
php --version
PHP 8.3.13 (cli) (built: Oct 30 2024 11:27:07) (NTS)