简体   繁体   English

LAMP:PHP无法正常工作(保留下载源文件而不是显示页面)

[英]LAMP: PHP not working (keeps downloading source file instead of displaying the page)

I bought online a server and installed on in (with 1-click, I didn't configure anything) LAMP. 我在线购买了一台服务器,并安装在(只需单击一下,就没有配置任何东西)LAMP中。 I now need to create a dynamic page using php, but if a create a file "test.php" with the following code: 我现在需要使用php创建动态页面,但是如果使用以下代码创建文件“ test.php”:

<?php
echo "Hello!";
?>

When I connect to " http://serverIP/test.php " instead of showing me an empty page which says "Hello!" 当我连接到“ http://serverIP/test.php ”时,没有显示空白页面显示“ Hello!”。 it keeps downloading test.php on my computer as a file! 它会继续将test.php作为文件下载到我的计算机上!

Please note: 'test.php' is in /var/www/html with index.html and many others .html files that work correctly. 请注意:“ test.php”位于/ var / www / html中,带有index.html和许多其他可以正常工作的.html文件。 If I type "php -v" in the command-line it says that php 7.0.22-0ubuntu0.16.04.1 is installed. 如果我在命令行中输入“ php -v”,则表示已安装php 7.0.22-0ubuntu0.16.04.1。 When I type "a2enmod php7.0" it says "Module php7.0 alredy enabled". 当我键入“ a2enmod php7.0”时,它显示“模块php7.0已启用”。 With LAMP i got installed Ubuntu 16.04 and Apache 2.4.18 (Ubuntu). 使用LAMP,我安装了Ubuntu 16.04和Apache 2.4.18(Ubuntu)。

I'm quite a newbie, so please help me... I have been searching for a solution for 3 days. 我是一个新手,所以请帮助我...我已经寻找了3天的解决方案。

This is my /etc/apache2/apache2.conf file (withot all the comments): 这是我的/etc/apache2/apache2.conf文件(没有所有注释):

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" 顺便说一句,我在“ / etc / apache2”中看不到名为“模块”的文件夹

You haven't loaded your module 您尚未加载模块

LoadModule php7_module 
modules/libphp7.so

原来LAMP使用的是nginx而不是Apache ...问题在这里解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM