Install PHP on Ubuntu

2022-09-13

Installation

This kind of installation supports multiple versions of PHP in the operating system. Don't forget to replace 8.3 by the exact version you need for your project and optionally install extensions:

sudo add-apt-repository ppa:ondrej/php
sudo apt install php8.3 \
    php8.3-cli \
    php8.3-curl \
    php8.3-gd \
    php8.3-gearman \
    php8.3-igbinary \
    php8.3-imagick \
    php8.3-mbstring \
    php8.3-memcached \
    php8.3-mysql \
    php8.3-opcache \
    php8.3-phpdbg \
    php8.3-readline \
    php8.3-sqlite3 \
    php8.3-xdebug \
    php8.3-xml \
    php8.3-yaml \
    php8.3-zip

Switching PHP versions

To switch PHP versions in Ubuntu Linux use this command:

sudo update-alternatives --config php