简体   繁体   English

更改 Apache http.conf 文件中的 documentroot 会停止 PHP 解析

[英]Changing documentroot in Apache http.conf file stops PHP parsing

  • Windows 10 workstation Windows 10 工作站
  • Apache 2.4阿帕奇 2.4
  • PHP 7.2. PHP 7.2。

I have installed Apache and PHP on a Windows 10 developer workstation and everything (including PHP) works beautifully.我已经在 Windows 10 开发人员工作站上安装了 Apache 和 PHP,一切(包括 PHP)都运行良好。 But when I change the DocumentRoot in the http.conf file, Apache stops sending .php files to the PHP engine.但是当我更改http.conf文件中的DocumentRoot时,Apache 停止向 PHP 引擎发送 .php 文件。

Apache opens the .php files in the new directory, but the <?php> code no longer gets parsed and processed by the php engine (php.exe). Apache 在新目录中打开 .php 文件,但 <?php> 代码不再被 php 引擎 (php.exe) 解析和处理。 Apache no longer runs those files through the php module. Apache 不再通过 php 模块运行这些文件。

Here is what I have changed in the http.conf file:这是我在 http.conf 文件中所做的更改:

OLD SETTING:旧设置:

DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">

NEW SETTING:新设置:

#DocumentRoot "${SRVROOT}/htdocs"
DocumentRoot "C:/WWW"

#<Directory "${SRVROOT}/htdocs">
<Directory "C:/WWW">

When I change it back again, PHP works just fine.当我再次更改它时,PHP 工作得很好。

I have also tried changing the doc_root setting in php.ini , but that does not help.我也尝试过更改php.inidoc_root设置,但这无济于事。 Apache loads the .php page, but does not send it to the php server. Apache 加载 .php 页面,但不会将其发送到 php 服务器。

Thank you for responding.谢谢你的回应。 The problem was a minor one.问题是一个小问题。 In the fresh install of PHP 5.3, the short_open_tag in PHP.ini was defaulted to Off .在 PHP 5.3 的全新安装中, PHP.ini中的short_open_tag默认为Off The phpinfo file in the Apache directory opened with <?php> and the file in the new directory opened with <?> , so it didn't parse. Apache 目录下的 phpinfo 文件用<?php>打开,新目录中的文件用<?>打开,所以没有解析。 I've changed the php.ini file with short_open_tag = On and all is well now.我已经用short_open_tag = On更改了 php.ini 文件,现在一切都很好。 In newer versions of PHP ... from 5.4 on up, the short open tag <?> will always work, regardless of the short_open_tag setting.在较新版本的 PHP 中 ... 从 5.4 开始,无论short_open_tag设置如何,短打开标签<?>将始终有效。

Simple little things can sometimes trip us up.简单的小事有时会让我们绊倒。

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

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