在Windows上为Apache设置PHP


Setting up PHP for Apache on Windows

我一直在尝试在Apache web服务器(localhost)中从PHP.net设置PHP。

在过去的一天半里,我一直在Apache网站、php.net网站、SO以及其他任何显示当前错误的地方查找文档,试图解决问题。以下是我目前的设置和(可能的)误解的一些细节。

Define SRVROOT "/Apache/00"
ServerRoot "${SRVROOT}"

Apache的公共目录设置为htdocs。Apache正在通过localhost毫无问题地生成其下目录的列表。为了确保我有正确的地址,而且是Apache,我做了一个如下所述的开/关测试。

我运行了为PHP提供的WindowsMSI。然后我调整了/conf/httpd.conf文件以添加:

ScriptAlias /php/ "${SRVROOT}/php/"
AddType application/x-httpd-php .php

注意:phphtdocs(公共文件)&conf目录都在同一目录SRVROOT的根目录中。

测试Apache

http://localhost/lib/ 

可能产生:

Index of /lib
    Parent Directory
    amd64/
    web.jar
    x86/

在关闭Apache并刷新列表时,我看到一个FF错误。

Unable to connect
Firefox can't establish a connection to the server at localhost.

所以Apache本身似乎运行得很好,当它运行时,我可以列出目录。

测试PHP

http://localhost/php/

显示:

Forbidden
You don't have permission to access /php/ on this server.

好吧,这似乎是合乎逻辑的,Apache现在承认目录的存在,但表示它不打算被公开浏览。

我在包含的php目录的根目录中有一个phpinfo.php

<?phpinfo();?>

我希望如果我浏览到http://localhost/phpinfo.php,应该会给我信息,但我得到了404消息:

Not Found
The requested URL /phpinfo.php was not found on this server.

对于http://localhost/php/phpinfo.php,我收到禁止消息:

Forbidden
You don't have permission to access /php/phpinfo.php on this server.

典型error.log

sl:warn] [pid 1504:tid 336] AH01909: RSA certificate configured for localhost:443 does NOT include an ID which matches the server name
[Sun Aug 04 19:06:01.995343 2013] [ssl:warn] [pid 1504:tid 336] AH02292: Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Sun Aug 04 19:06:02.298078 2013] [ssl:warn] [pid 1504:tid 336] AH01909: RSA certificate configured for localhost:443 does NOT include an ID which matches the server name
[Sun Aug 04 19:06:02.298078 2013] [ssl:warn] [pid 1504:tid 336] AH02292: Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Sun Aug 04 19:06:02.300031 2013] [mpm_winnt:notice] [pid 1504:tid 336] AH00354: Child: Starting 64 worker threads.
[Sun Aug 04 19:06:03.279523 2013] [authz_core:error] [pid 1504:tid 1004] [client ::1:50589] AH01630: client denied by server configuration: I:/Apache/00/php/index.html
[Sun Aug 04 19:15:39.932843 2013] [authz_core:error] [pid 1504:tid 1004] [client ::1:50599] AH01630: client denied by server configuration: I:/Apache/00/php/
[Sun Aug 04 19:21:49.700421 2013] [authz_core:error] [pid 1504:tid 1004] [client ::1:50608] AH01630: client denied by server configuration: I:/Apache/00/php/phpinfo.php
[Sun Aug 04 19:26:58.432843 2013] [authz_core:error] [pid 1504:tid 1004] [client ::1:50621] AH01630: client denied by server configuration: I:/Apache/00/php/phpinfo.php
[Sun Aug 04 19:37:26.403546 2013] [mpm_winnt:notice] [pid 4400:tid 324] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Sun Aug 04 19:37:28.403546 2013] [mpm_winnt:notice] [pid 1504:tid 336] AH00364: Child: All worker threads have exited.
[Sun Aug 04 19:37:28.418195 2013] [mpm_winnt:notice] [pid 4400:tid 324] AH00430: Parent: Child process 1504 exited successfully.

问题

我想展示phpinfo.php文档。有人能看到我犯的愚蠢错误吗(我是这方面的新手)?

另请参阅:

这些是我一直在看的主要文档:

  • http://httpd.apache.org/docs/2.4/
  • http://www.php.net/docs.php

您可能会收到权限错误,因为phpinfo.php文件没有设置权限,因此您正在运行的Apache服务器可以读取它。Apache可以配置为在运行时将权限授予有限的用户帐户,如果您对某个文件的文件安全权限不允许该用户帐户读取该文件,您将收到权限错误。请记住,这适用于最终路径名中的每个目录,即/Apache和/Apache/00/phph和/Apachi/00/phpinfo.php必须全部可由Apache运行的用户帐户读取。

另一种可能性是,如果httpd.conf有一个默认访问策略deny-first的Directory指令,那么您可能需要在httpd.conf中添加一个Directory指令,以允许访问/php/。

我也没有看到任何关于您在Apache模块文件夹中安装PHP Apache模块DLL的地方,也没有提到您在httpd.conf文件中添加模块的地方。如果不加载PHP模块,PHP文件将不会通过PHP。