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 (Link seems to be broken now)

    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