I got this kind of problem. This is how I solve it. After installed Apache then I installed PHP using this command.
sudo apt-get install php libapache2-mod-php
it executes correctly but I request .php file from Apache, it gives without executing the PHP script.
Then I check PHP is enabled.
$ cd /etc/apache2
$ ls -l mods-*/*php*
but it didn't show any results. I check installed PHP packages.
$ dpkg -l | grep php| awk '{print $2}' |tr "\n" " "
Different type of PHP versions installed to my computer. Then I remove some PHP packages from my previous list, using apt-get purge.
sudo apt-get purge libapache2-mod-php7.0 php7.0 php7.0-cli php7.0-common php7.0-json
I reinstall PHP
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
Verify that the PHP module is loaded
$ a2query -m php7.0
if not enabled with:
$ sudo a2enmod php7.0
Restart Apache server
$ sudo systemctl restart apache2
Finally, I check PHP process on Apache
create an empty file
sudo vim /var/www/html/info.php
Add this content to info.php & save.
<?php
phpinfo();
?>
Check on browser:
it shows correctly.I think this will help anyone.