简体   繁体   English

Raspbian Jessie上的Apache2不执行php文件

[英]Apache2 on Raspbian Jessie not executing php files

I have installed apache2 and php 5 on my raspeberry pi 3 using the following: 我已经使用以下命令在raspeberry pi 3上安装了apache2和php 5:

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

When I point a browser at the pi via the IP address, I get the "it works" apache page, so it seems all is good ... until I try to access a simple .php file via http://192.168.1.102/test.php . 当我通过IP地址将浏览器指向pi时,我得到了“它有效”的apache页面,因此似乎一切都很好……直到我尝试通过http://192.168.1.102访问一个简单的.php文件。 /test.php

Test .php look like this: 测试.php如下所示:

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

When I point a browser at that file as described above, it opens the file in a text editor rather than executing it. 如上所述,当我将浏览器指向该文件时,它将在文本编辑器中打开该文件,而不是执行该文件。

Running a2enmod php5 returns "module php5 already enabled" 运行a2enmod php5返回“模块php5已启用”

test.php is in var/www/html test.php在var / www / html中

I looked at PHP code is not being executed, instead code shows on the page , and the answers do not solve my problem. 我看着PHP代码没有被执行,而是页面上显示了代码 ,而答案并不能解决我的问题。 Mainly, the most popular/relevant answer has me editing httpd.conf, which does not exist in my installation. 主要是,最流行/最相关的答案是让我编辑httpd.conf,该文件在我的安装中不存在。

Here is point-by-point notes for the most popular answer to that post: 以下是该帖子最受欢迎的答案的逐点注释:

  1. Make sure that PHP is installed and running correctly. 确保PHP已安装并正确运行。 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. 一种简单的检查方法是从命令行运行php -v,看看是否返回版本信息或任何错误。
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. 确保在Apache的httpd.conf中列出并取消注释了PHP模块。该文件应该类似于文件中的LoadModule php5_module“ c:/php/php5apache2_2.dll”。 Search for LoadModule php, and make sure that there is no comment (;) in front of it. 搜索LoadModule php,并确保它前面没有注释(;)。

Under the directory /etc/apache2, in file apache2.conf: 在目录/ etc / apache2下,文件apache2.conf中:

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

Under the directory /etc/apache2/mods-enabled, in file php5.load: 在目录/ 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. 确保Apache的httpd.conf文件中包含PHP MIME类型。 This should be something like AddType application/x-httpd-php .php. 这应该类似于AddType application / x-httpd-php .php。 This tells Apache to run .php files as PHP. 这告诉Apache将.php文件作为PHP运行。 Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented. 搜索AddType,然后确保有一个PHP条目,并且没有注释。

Under the directory /ect/apache2/mods-enabled, in file php5.conf: 在目录/ 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. 确保文件上带有.php扩展名,或第3点在MIME定义中指定的任何扩展名,否则它将不会作为PHP执行。

They do. 他们是这样。

  1. Make sure you are not using short tags in the PHP file ( < ?), these are deprecated not enabled on all servers by default. 确保您没有在PHP文件中使用短标签( < ?),默认情况下,所有服务器上均不启用短标签。 Use < ?php instead (or enable short tags in your php.ini with short_open_tag=On if you have code that relies on them). 使用< ?php代替(或者如果您有依赖于它们的代码,则在php.ini中使用short_open_tag = On启用短标记)。

Double-checked this. 仔细检查一下。

  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://localhost/file.php之类的URL,而不是通过本地文件访问file://localhost/www/file.php通过Web服务器访问文件。

I am accessing with http. 我正在访问http。 Tried both local (same computer) and remote (computer on my network), with the same results. 尝试了本地(同一台计算机)和远程(我的网络上的计算机),结果相同。

Not sure what other info is of interest, but I've searched all over the net and not been able to find a solution that works (most go back to installing as above). 不知道还需要其他什么信息,但是我已经在网上搜索了所有信息,却找不到有效的解决方案(大多数返回到上面的安装)。 I even completely purged and re-installed. 我什至完全清除并重新安装。

Thanks in advance for any help. 在此先感谢您的帮助。

Ok, finally figured this out! 好的,终于明白了!

Turns out that, in a different evolution, my son had installed nginx. 事实证明,以另一种演变,我儿子安装了nginx。 So that was what was running. 这就是运行情况。 Removing nginx solved the problem. 删除nginx解决了该问题。 Turns out I was trying to figure why Apache wasn't doing what I expected, but it wasn't apache tat was serving the site! 原来我试图弄清楚为什么Apache没有按照我的预期去做,但是不是Apache为该站点提供服务!

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

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