【问题标题】:PHP file is not executing codePHP文件没有执行代码
【发布时间】:2015-06-09 04:56:22
【问题描述】:
My PHP code is not executed when I access the root directory with

http://localhost/sample.php

我要运行的代码是:

<?php phpinfo(); ?>

但我的代码只是显示在浏览器上,并没有执行。

我尝试过:

  • 多次重启所有服务,包括将 WampServer 上线;
  • httpd.conf中的监听端口改为8080。

PHP 错误日志中没有任何错误,但 Apache 错误日志中出现以下错误:

[Tue Jun 09 08:53:52 2015] [notice] Apache/2.2.21 (Win32) PHP/5.3.10     configured -- resuming normal operations

[Tue Jun 09 08:56:30 2015] [error] [client ::1] client denied by server configuration: C:/wamp/www/
[Tue Jun 09 08:56:30 2015] [error] [client ::1] client denied by server     configuration: C:/wamp/www/favicon.ico, referer: http://localhost/
[Tue Jun 09 09:22:23 2015] [error] [client ::1] (20023)The given path was     above the root path: Cannot map GET /C:/wamp/www HTTP/1.1 to file
[Tue Jun 09 09:22:24 2015] [error] [client ::1] client denied by server     configuration: C:/wamp/www/favicon.ico, referer: http://localhost/C:/wamp/www
[Tue Jun 09 09:26:26 2015] [error] [client ::1] client denied by server     configuration: C:/wamp/www/
[Tue Jun 09 09:26:26 2015] [error] [client ::1] client denied by server configuration: C:/wamp/www/favicon.ico, referer: http://localhost/
[Tue Jun 09 09:26:46 2015] [error] [client ::1] client denied by server     configuration: C:/wamp/apps/phpmyadmin3.4.10.1/
[Tue Jun 09 09:26:46 2015] [error] [client ::1] client denied by server configuration: C:/wamp/www/favicon.ico, referer: http://localhost/phpmyadmin/
[Tue Jun 09 09:30:10 2015] [error] [client ::1] client denied by server     configuration: C:/wamp/apps/phpmyadmin3.4.10.1/
[Tue Jun 09 09:30:10 2015] [error] [client ::1] client denied by server     configuration: C:/wamp/www/favicon.ico, referer: http://localhost/phpmyadmin/
[Tue Jun 09 09:31:21 2015] [error] [client ::1] client denied by server configuration: C:/wamp/apps/phpmyadmin3.4.10.1/
[Tue Jun 09 09:31:21 2015] [error] [client ::1] client denied by server configuration: C:/wamp/www/favicon.ico, referer: http://localhost/phpmyadmin/

【问题讨论】:

  • 您检查过 apache 目录中的 access.log 文件吗?它可能会显示一些错误消息。如果有,请与我们分享,我们可以提供帮助。
  • 不,我以前没有检查过,但现在我打开它,我提出了很多 Get 请求,其中一些是 ::1 - - [09/Jun/2015:08:56:30 +0530] "GET / HTTP/1.1" 403 202 ::1 - - [09/Jun/2015:08:56:30 +0530] "GET /favicon.ico HTTP/1.1" 403 213 ::1 - - [09/Jun/2015:09:22:23 +0530] "GET /C:/wamp/www HTTP/1.1" 403 213
  • 您确定您使用的是正确版本的 wampserver 吗?我的意思是 x86 和 x64。更重要的是:您的项目目录在哪里?更改其位置,如 C:\project 并重试。
  • 我第一次尝试使用 PHP .. 我尝试执行的 php 文件位于 c:\wamp\www 中。我不确定 wamp 服务器的版本
  • 检查 error_log 文件。有什么不寻常的地方,比如那里的任何错误?如果有,请更新您的帖子并与我们分享。

标签: php apache wamp


【解决方案1】:

您的问题是您的浏览器已决定使用 IPV6 堆栈而不是 IPV4 堆栈,因此错误消息中的 IP 地址::1 而不是更常见的“127.0.0.1”IPV4 环回地址。

由于 Apache/2.2.21 Apache 附带的 WAMPServer 版本发布时 IPV6 非常新,并且未配置为期望从 IPV6 环回地址::1 访问,因此您必须修改配置。

使用 wampmanager 菜单编辑 httpd.conf 以确保编辑正确的文件。然后寻找这个部分,它可能看起来像这样:-

<Directory "c:/wamp/www/">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride all

    #
    # Controls who can get stuff from this server.
    #

#   onlineoffline tag - don't remove
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1 

</Directory>

所以改变这些行如下

#   onlineoffline tag - don't remove
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1 ::1 localhost     <-- this line

看到我添加了IP地址::1localhost

您还必须以相同的方式更改控制对 phpMyAdmin 的访问的文件:-

编辑 \wamp\alias\phpmyadmin.conf 并更改

Order Deny,Allow
Deny from all
Allow from localhost 127.0.0.1

Order Deny,Allow
Deny from all
Allow from localhost 127.0.0.1 ::1

如果您实际使用这些功能,您可能还需要以相同的方式修改 sqlbuddy 和 webgrind 配置。

【讨论】:

    【解决方案2】:

    我假设您使用的是 Windows 8。
    试试这些:
    1.在httpd.conf文件中,更改 Listen 80Listen 127.0.0.1:8080
    2.禁用windows防火墙。如果它以这种方式工作,您需要打开端口 8080(向 Windows 防火墙添加例外)。
    3.如果有服务使用8080端口,请停止这些服务,重启wampserver再试。
    4. 如果这些都不适合您,请尝试在您的 wampserver apache 配置文件 (httpd.conf) 中更改这些行,并在保存后重新启动 apache 服务器。

    Order Deny, Allow
    Deny from all
    Allow from 127.0.0.1 :: 1 localhost
    Allow from 192.168
    Allow from 10.186
    

    【讨论】:

    • 这里有httpd.conf.bulid命名的文件。这是我需要更改的文件吗
    • 它是:c:\wamp\bin\apache\Apache(apacheversion)\conf\httpd.conf 文件。那里没有httpd.conf文件吗?
    【解决方案3】:

    首先检查您的本地主机是否正在运行 http://localhost

    如果它不起作用,那么它可能因为 8080 端口冲突而为 apache 分配了一些其他端口。即使这样也不能解决你的问题,那么摆脱这个问题的最快和最简单的方法是重新安装你的 wampserver 从这里下载它http://www.wampserver.com/en/ 那里提供了一个很好的安装说明。

    【讨论】:

      猜你喜欢
      • 2012-05-22
      • 2012-01-12
      • 1970-01-01
      • 1970-01-01
      • 2019-07-23
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      相关资源
      最近更新 更多