How to get PHP 7.0 running with Apache2

I am totally new to Linux, servers and websites. I recently set up Apache2, Python, PHP, and MySQL for setting up a LAMP server. I am using Xubuntu 16.04 and PHP 7.0.11. I followed a guide and placed a PHP file named testing.php in it with:

<?php phpinfo(); ?> 

It doesn't show anything on localhost/testing.php All it shows is the code itself.


Solution 1:

Open the terminal and type:

sudo apt install libapache2-mod-php7.0 # install PHP7 module for Apache2 webserver
sudo a2enmod php7.0 # enable the PHP7 module
sudo service apache2 reload # restart apache  

For PHP 7.2 in Ubuntu 18.04 run the following commands:

sudo apt install libapache2-mod-php7.2  
sudo a2enmod php7.2  
sudo systemctl restart apache2.service