PHP 文件未执行代码

PHP file is not executing code

My PHP code is not executed when I access the root directory with

http://localhost/sample.php

我想要运行的代码是:

<?php phpinfo(); ?>

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

我试过:

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/

我假设您使用的是 windows 8.
试试这些:
1. 在 httpd.conf 文件中,更改 Listen 80 线路 Listen 127.0.0.1:8080
2. 禁用 windows 防火墙。如果它以这种方式工作,则需要打开端口 8080(向 windows 防火墙添加例外)。
3.如果有服务使用8080端口,停止这些服务,重启wampserver再试。
4. 如果其中 none 适合您,请尝试在您的 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

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

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

您的问题是您的浏览器已决定使用 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 配置。