Apache shows PHP code instead of executing it
open the file
/etc/apache2/httpd.conf
and change
#LoadModule php5_module libexec/apache2/libphp5.so
into
LoadModule php5_module libexec/apache2/libphp5.so
So just uncoment the PHP module load in httpd.conf
For PHP 7 (May apply to previous versions as well), but I had to do this:
Add this to the bottom of /etc/apache2/apache2.conf
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Run this from the terminal:
sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7
Then don't forget to restart Apache so it knows you changed stuff:
sudo service apache2 restart
This is a summary from: https://www.atlantic.net/community/howto/try-php7-lamp-ubuntu-14-04/
You must enable php! Check the folder mods-enabled
in the Apache directory (default: /etc/apache2/
) to see if you find a file named php
. I don't remember the extension but I think it's .so
.
Also check in /var/log/apache2/error.log
to see if you have any other errors.
Wow, lots of solutions here! Here's what I did on Ubuntu 16.04:
sudo apt-get install php libapache2-mod-php
sudo a2enmod mpm_prefork && sudo a2enmod php7.0
sudo service apache2 restart