PHP and Apache2 on Ubuntu — clean install for Composer

I ran into multiple issues getting a clean Composer setup:

WARNING: Module json ini file doesn't exist under /etc/php/7.2/mods-available
Moodle requires the json PHP extension. Please install or enable the json extension.

The root cause was leftover configuration from a previous install. The fix: fully purge both PHP and Apache2, including their config files, then reinstall from scratch.

Warning: This removes all Apache and PHP configuration. Back up php.ini and apache2.conf first if you need them.

sudo apt purge php*
sudo apt purge apache2*
sudo apt install apache2
sudo apt install php libapache2-mod-php php-mysql
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

The purge command (unlike remove) also deletes configuration files — that's the key step.