简体   繁体   中英

PHP file is not executing code

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

http://localhost/sample.php

The code I want to run is:

<?php phpinfo(); ?>

But my code is just shown on the browser, it is not executing.

I tried to:

  • restart all services several times including putting WampServer online;
  • changing the listening port in httpd.conf to 8080.

There is not any error in the PHP error log But in Apache Error Log there are errors as following:

[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/

I assume that you are using windows 8.
Try these:
1. In httpd.conf file, change Listen 80 line with Listen 127.0.0.1:8080
2. Disable windows firewall. If it works that way, you need to open your port 8080 (adding an exception to windows firewall).
3. If there are any services using port 8080, stop these services, restart wampserver and try again.
4. If none of these works for you, try to change these lines in your wampserver apache configuration file (httpd.conf) and after saving, restart the apache server.

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

First check your localhost is running or not by http://localhost

if it was not working then it could because of 8080 port conflict assign some other port to apache.Even this could not solve your problem then fastest and easiest way to get rid of this thing is by reinstalling your wampserver download it from here http://www.wampserver.com/en/ a nice installation description provided there.

Your problem is that your browser has decided to use the IPV6 stack rather than the IPV4 stack hence the ip address ::1 in the error messages rather that the more usual `127.0.0.1' IPV4 loopback address.

As IPV6 was very new when the version of WAMPServer that comes with Apache/2.2.21 Apache was released, and is not configured to expect access from the IPV6 loopback address ::1 so you will have to amend the config.

Edit httpd.conf using the wampmanager menus to make sure you edit the correct file. Then look for this section, it will probably look something like this :-

<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>

So change these lines as follows

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

See I have added the ip address ::1 and also localhost

You will also have to change the file that controls access to phpMyAdmin in the same way :-

Edit \\wamp\\alias\\phpmyadmin.conf and change

Order Deny,Allow
Deny from all
Allow from localhost 127.0.0.1

To

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

You may also need to amend the sqlbuddy and webgrind configs in the same way if you actually use those features.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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