简体   繁体   English

Apache 2.4:PHP文件未发送到浏览器

[英]Apache 2.4: PHP files are not being sent to the browser

I'm setting up a new site locally on a Windows machine for testing. 我正在Windows机器上本地设置一个新站点进行测试。 In the document root, if I have an index.html it is served to the browser without problem. 在文档根目录中,如果我有index.html它将毫无问题地提供给浏览器。 If I rename it index.php , the browser receives nothing. 如果我将其重命名为index.php ,浏览器将什么也不会收到。 No error is raised server-side. 服务器端未引发任何错误。 I'm trying to understand why. 我想了解原因。

Vhosts 虚拟主机

<VirtualHost *:80>
    DocumentRoot "C:\websites\learn"
    ServerName learn.loc

    LogLevel alert rewrite:trace2

    #PHP SETTINGS   
    php_value auto_prepend_file "C:\websites\learn\noop.php"
    php_value open_basedir "C:\websites\learn"

    <Directory "C:\websites\learn">    
      Options Indexes FollowSymLinks
      AllowOverride All
      Require all granted
    </Directory>   

</VirtualHost>

Here is the .htaccess file that resides in the document root: 这是位于文档根目录中的.htaccess文件:

RewriteEngine on
#point to javascript learning project
RewriteRule ^js   /javascript
RewriteRule ^js/(.*)   /javascript/$1

Here is the mod_rewrite log generated when I load learn.loc/javascript (this folder has an index.php file) 这是我加载learn.loc/javascript时生成的mod_rewrite日志(此文件夹具有index.php文件)

[initial] [perdir C:/websites/learn/] pass through C:/websites/learn/javascript/
[subreq] [perdir C:/websites/learn/] pass through C:/websites/learn/javascript/index.html
[subreq] [perdir C:/websites/learn/] pass through C:/websites/learn/javascript/index.htm
[subreq] [perdir C:/websites/learn/] pass through C:/websites/learn/javascript/index.php

Nothing is added to Apache or PHP error log; 什么也没有添加到Apache或PHP错误日志中; The browser itself receives status code 200 , along with the following response headers 浏览器本身接收status code 200以及以下响应标头

Date:           "..."
Server:         "Apache/2.4.16 (Win32) PHP/5.6.23"
X-Powered-By:   "PHP/5.6.23"
Content-Length: "0"
Keep-Alive:     "timeout=5, max=100"
Connection:     "Keep-Alive"
Content-Type:   "text/html; charset=UTF-8"

The response body is an empty string. 响应主体是一个空字符串。 Like I said, if I rename the file to index.html the content (vanilla html file) is shown. 就像我说的,如果我将文件重命名为index.html ,则会显示内容(原始html文件)。 What could be going on? 可能会发生什么?

I figured it out. 我想到了。 That was just me being careless. 那只是我粗心。 The problem was with this line from Vhosts config: 问题出在Vhosts配置中的这一行:

php_value auto_prepend_file "C:\websites\learn\noop.php"

More specifically, what was supposed to be a noop was really an execution killer. 更具体地说,本来应该是没有行动的人实际上是一个执行杀手。

noop.php noop.php

<?php
exit; // <- exits not just this script but all of PHP and returns to the browser

Once I removed the 2nd line, things were back in order. 一旦我删除了第二行,一切就恢复了正常。 This also explains why renaming index.php to index.html got things working: it took PHP out of the loop entirely. 这也解释了为什么将index.php重命名为index.html可以正常工作:PHP完全退出了循环。

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

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