【发布时间】:2017-11-07 20:51:49
【问题描述】:
我在网上购买了一台服务器并安装在(通过一键点击,我没有配置任何东西)LAMP。 我现在需要使用php创建一个动态页面,但是如果使用以下代码创建一个文件“test.php”:
<?php
echo "Hello!";
?>
当我连接到“http://serverIP/test.php”而不是显示“你好!”的空白页面时它不断在我的电脑上下载 test.php 作为文件!
请注意:“test.php”位于 /var/www/html 中,其中包含 index.html 和许多其他可以正常工作的 .html 文件。 如果我在命令行中键入“php -v”,则表示已安装 php 7.0.22-0ubuntu0.16.04.1。 当我输入“a2enmod php7.0”时,它显示“模块 php7.0 已启用”。 使用 LAMP,我安装了 Ubuntu 16.04 和 Apache 2.4.18 (Ubuntu)。
我是一个新手,所以请帮助我...我已经寻找了 3 天的解决方案。
这是我的 /etc/apache2/apache2.conf 文件(没有所有 cmets):
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>
顺便说一句,我在“/etc/apache2”中看不到名为“modules”的文件夹
【问题讨论】:
-
启用 PHP 模块后一定要重启 Apache。如果问题仍然存在,我建议联系服务器公司寻求帮助。正在下载的 PHP 文件表明 Web 服务器配置错误;即,未配置为响应对
.php文件的请求。 -
我总是在测试前重启 Apache...我添加了我的 apache2.conf 的代码,希望对您有所帮助