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