LAMP: PHP not working (keeps downloading files.php)

November 7, 2017 6.7k views
Apache PHP DigitalOcean Ubuntu 16.04

Installed with a 1-click LAMP on my droplet (2 weeks ago).
I now need to create a dynamic page using php, but if a create a file “test.php” with the following code:

echo "Hello!";

instead of showing me an empty page which says “Hello!” it keeps downloading me test.php on my computer (when I connect to http://myip/test.php")!
Please note: ‘test.php’ is in /var/www/html with index.html and many other .html files that work correctly.
If I type php -v in the command-line it says that php 7.0.22-0ubuntu0.16.04.1 is installed.
With LAMP i got installed Ubuntu 16.04 and Apache 2.4.18 (Ubuntu).
When I type a2enmod php7.0 it says “Module php7.0 alredy enabled”.

I’m quite a newbie, so please help me… I have been searching for a solution for 2 days

2 Answers

Problem solved… turned out that LAMP used Nnginx instead of Apache…
Here the solution

Check your httpd.conf file and see if your LoadModule php (it’ll look something like LoadModule php7module modules/ is commented out. If it is, uncomment it.

  • This is at the bottom of my /etc/apach2/apache2.conf:

    LoadModule php7_module modules/
    AddType application/x-httpd-php .php
    <FilesMatch \.php$>
        SetHandler application/x-httpd-php

    Still doesn’t work… and I can’t see a modules folder in /etc/apache2: there are 6 folders (mods-available, mods-enabled, conf-available, conf-enabled, sites-available, sites-enabled)

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!