PHP
Check current π
php --version
Install current version π
See apache install instructions to see how to install the current version that is in the default repos.
Install multiple versions π
Source: https://www.youtube.com/watch?v=bHTv0FmvrTo
- Before doing this process it is assumed that apache and the current version of php is already installed.
- This approach only allows you to use one version at a time on the system.
- Tested on Ubuntu 22.04
Install dependency π
NB: Normally already installed
sudo apt install software-properties-common
Add ppa for other versions π
Previous step needed to ensure this command is available.
sudo add-apt-repository ppa:ondrej/php
Install desired version π
Replace 7.3 in the example with the version you are looking for
sudo apt install php7.3
Select versions of PHP that are installed and available π
For Apache π
Source: https://serverfault.com/questions/149039/how-to-change-what-version-of-php-apache2-uses
Example commands switch from 8.1 to 7.3
NB: Use of tab
to autocomplete commands works and helped in ensuring I got the version numbers right.
Disable current module π
sudo a2dismod php8.1
Enable replacement version π
sudo a2enmod php7.3
Install MySQL Module for PHP π
Source: https://zoomadmin.com/HowToInstall/UbuntuPackage/php-mysqli
sudo apt install php7.3-mysql
Restart Apache π
See instructions on restarting apache here.
For CLI π
Will open a menu showing which are installed, and which one is active.
NB: sudo
not needed to only view the list and see which is active.
sudo
is only needed if you want to change the selection.
sudo update-alternatives --config php