My PHP code is not executed when I access the root directory with
http://localhost/sample.php
我想要运行的代码是:
<?php phpinfo(); ?>
但是我的代码只是在浏览器上显示,它没有执行。
我试图:
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/
答案 0 :(得分:1)
我假设您使用的是Windows 8
试试这些:
1.在httpd.conf文件中,更改
收听80 行收听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
答案 1 :(得分:1)
首先检查您的localhost是否正在运行 http://localhost
如果它不工作那么它可能因为8080端口冲突分配一些其他端口到apache。即使这无法解决你的问题然后最快和最简单的方法来摆脱这件事是通过重新安装你的wampserver从这里下载它http://www.wampserver.com/en/提供了很好的安装说明。
答案 2 :(得分: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地址::1
以及localhost
您还必须以相同的方式更改控制对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配置。