0

I bought online a server and installed on in (with 1-click, I didn't configure anything) LAMP. I now need to create a dynamic page using php, but if a create a file "test.php" with the following code:

<?php
echo "Hello!";
?>

When I connect to "http://serverIP/test.php" instead of showing me an empty page which says "Hello!" it keeps downloading test.php on my computer as a file!

Please note: 'test.php' is in /var/www/html with index.html and many others .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. When I type "a2enmod php7.0" it says "Module php7.0 alredy enabled". With LAMP i got installed Ubuntu 16.04 and Apache 2.4.18 (Ubuntu).

I'm quite a newbie, so please help me... I have been searching for a solution for 3 days.

This is my /etc/apache2/apache2.conf file (withot all the comments):

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
Include ports.conf
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf


#the following lines are what I added
LoadModule php7_module modules/libphp7.so
AddType application/x-httpd-php .php
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

By the way, I can't see a folder named "modules" in "/etc/apache2"

MauroFari
  • 13
  • 4
  • Be sure to restart Apache after enabling the PHP module. If problems persist, I suggest contacting the server company for assistance. PHP files being downloaded are an indication of a misconfigured web server; i.e., one that is not configured to respond to requests for `.php` files. – jaswrks Nov 08 '17 at 05:41
  • I always restart Apache before testing... I added the code of my apache2.conf, I hope that will help – MauroFari Nov 08 '17 at 17:19

2 Answers2

0

You haven't loaded your module

LoadModule php7_module 
modules/libphp7.so
rai
  • 449
  • 3
  • 10
  • Now, this is the bottom of the apache2.conf: LoadModule php7_module modules/libphp7.so AddType application/x-httpd-php .php SetHandler application/x-httpd-php (Still doesn't work. By the way, i can't see a "modules" folder in "/etc/apache2" – MauroFari Nov 08 '17 at 17:36
0

It turned out LAMP was using nginx instead of Apache... problem solved here

MauroFari
  • 13
  • 4