PHP toolcase

Getting information

Display installed versions

To list the installed versions and select the default version you can use the command:

sudo update-alternatives --config php

Display installed modules

This will display installed modules for default PHP:

php -m

Interactive shell

You can run the interactive shell from any terminal:

php -a

Install PHP

Core install

Add APT repository:

sudo add-apt-repository ppa:ondrej/php

Update repository:

sudo apt update

Install PHP core (module for apache is optional):

sudo apt install php8.0 libapache2-mod-php

Basic Module install

sudo apt install openssl php8.0 php8.0-bcmath php8.0-mbstring php8.0-xml php8.0-curl php8.0-zip php8.0-mysql

Basic module install 7.2

sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-mysql \
php7.2-xml php7.2-xmlrpc php7.2-curl php7.2-gd \
php7.2-imagick php7.2-cli php7.2-dev php7.2-imap \
php7.2-mbstring php7.2-soap php7.2-zip -y

Basic Module Install 8.2

sudo apt install php8.2-common php8.2-mysql php8.2-xml php8.2-xmlrpc php8.2-curl php8.2-gd php8.2-imagick php8.2-cli php8.2-dev php8.2-imap php8.2-mbstring php8.2-opcache php8.2-soap php8.2-zip php8.2-redis php8.2-intl -y

Test PHP

Test PHP is running correctly:

php -r 'echo "Hello world";'