PHP not working after upgraded to Ubuntu 17.10

After I upgraded to Ubuntu 17.10, PHP totally stopped working. Everything works fine in Ubuntu 17.04. The code for info.php as follows does not work:

<?php 
phpinfo();
?>

It is not showing PHP information, it only shows the source code like above.


Open terminal with ALT + CTRL + T and type in these commands:

sudo a2enmod php7.1
sudo systemctl restart apache2

libapache2-mod has been upgraded from libapache2-mod-php7.0 in Ubuntu 17.04 to libapache2-mod-php7.1 in Ubuntu 17.10 and Ubuntu 18.04. Open the terminal and type:

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