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

时间:2017-07-17 23:47:06

标签: php apache

我在Windows计算机上本地设置新网站以进行测试。在文档根目录中,如果我有一个self.meridians = self.basemap_ax.drawmeridians(numpy.around(numpy.degrees(coord_lons)), labels=[1,0,0,1], labelstyle='+/-', fmt='%g' + 'E', linewidth=0.5, color='gray', yoffset=5) ,它会毫无问题地提供给浏览器。如果我将其重命名为index.html,则浏览器不会收到任何内容。服务器端没有出现错误。我试图了解原因。

虚拟主机

index.php

以下是文档根目录中的<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> 文件:

.htaccess

以下是我加载RewriteEngine on #point to javascript learning project RewriteRule ^js /javascript RewriteRule ^js/(.*) /javascript/$1 时生成的mod_rewrite日志(此文件夹有learn.loc/javascript个文件)

index.php

Apache或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 以及以下响应标头

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" ,则会显示内容(vanilla html文件)。会发生什么事?

1 个答案:

答案 0 :(得分:0)

我明白了。那只是我粗心大意。问题在于来自Vhosts config的这一行:

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

更具体地说,本来应该是noop的确是一个执行杀手。

<强> noop.php

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

一旦我删除了第二行,事情就恢复了。这也解释了为什么将index.php重命名为index.html让事情变得有效:它完全将PHP带出了循环。