Raspbian Jessie 上的 Apache2 未执行 php 个文件

Apache2 on Raspbian Jessie not executing php files

我已经使用以下命令在我的树莓派 3 上安装了 apache2 和 php 5:

apt-get -y install apache2
apt-get -y install php5 libapache2-mod-php5

当我通过 IP 地址将浏览器指向 pi 时,我得到了 "it works" apache 页面,所以看起来一切都很好......直到我尝试访问一个简单的 .php 文件通过 http://192.168.1.102/test.php.

测试 .php 看起来像这样:

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php phpinfo(); ?> 
 </body>
</html>

当我如上所述将浏览器指向该文件时,它会在文本编辑器中打开文件而不是执行它。

运行 a2enmod php5 returns"module php5 already enabled"

test.php 在 var/www/html

我查看了 PHP code is not being executed, instead code shows on the page,答案并没有解决我的问题。主要是,最 popular/relevant 的答案让我编辑 httpd.conf,我的安装中不存在它。

以下是最常见答案的逐点说明 post:

  1. Make sure that PHP is installed and running correctly. This may sound silly, but you never know. An easy way to check is to run php -v from a command line and see if returns version information or any errors.
pi@raspberrypi:/ $ php -v
PHP 5.6.30-0+deb8u1 (cli) (built: Apr 14 2017 16:20:58) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
  1. Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like LoadModule php5_module "c:/php/php5apache2_2.dll" in the file. Search for LoadModule php, and make sure that there is no comment (;) in front of it.

目录/etc/apache2下,文件apache2.conf中:

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

目录/etc/apache2/mods-enabled下,文件php5.load:

LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
  1. Make sure that Apache's httpd.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php. This tells Apache to run .php files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.

目录/ect/apache2/mods-enabled下,文件php5.conf中:

<FilesMatch ".+\.ph(p[345]?|t|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>
  1. Make sure your file has the .php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.

他们有。

  1. Make sure you are not using short tags in the PHP file (<?), these are deprecated not enabled on all servers by default. Use <?php instead (or enable short tags in your php.ini with short_open_tag=On if you have code that relies on them).

仔细检查。

  1. Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php

我正在使用 http 访问。尝试了本地(同一台计算机)和远程(我网络上的计算机),结果相同。

不确定还有哪些其他信息值得关注,但我在网上进行了搜索,但未能找到有效的解决方案(大多数返回到如上所述的安装)。我什至完全清除并重新安装。

在此先感谢您的帮助。

好的,终于明白了!

原来,在不同的演变中,我的儿子安装了 nginx。这就是 运行。删除 nginx 解决了这个问题。结果我试图弄清楚为什么 Apache 没有按照我的预期去做,但它不是 apache tat 在为该网站提供服务!