PHP showing as text after upgrade to Ubuntu 18.04

Description of the issue:

PHP files show as plain text in the web browser using a valid http request.

When the issue occured:

During the upgrade to Ubuntu 18.04, you might have chosen, as I did, to remove outdated packages, which has removed PHP 7.1

Noticing that, you certainly installed PHP 7.2 with the command:

sudo apt install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php

and restart the apache server:

sudo service apache2 restart

Source: https://howtoubuntu.org/how-to-install-lamp-on-ubuntu

This might have not solved the issue.

If reinstalling PHP is indeed required, what brought back PHP was the following:

sudo a2enmod php7.2
sudo service apache2 restart

Indeed, in addition to reinstalling apache2, you need to re-activate php-mod in apache2. This is the meaning of a2enmod php7.2.

  a2enmod  is  a  script that enables the specified module within the apache2 configuration.

Source:  http://manpages.ubuntu.com/manpages/trusty/man8/a2enmod.8.html

TLDNR / Solution:

sudo apt install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php
sudo a2enmod php7.2
sudo service apache2 restart