Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache shows PHP code instead of executing it

Tags:

php

apache

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

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/


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


I found this to solve my related problem. I added it to the relevant <Directory> section:

<IfModule mod_php5.c>
    php_admin_flag engine on
</IfModule>