问题
My php code is not executed when I access the root directory with
http://localhost:8080/sample.html
The code I want to run is:
<?php phpinfo(); ?>
and I tried also the following:
- Restarted all services several times including putting Wamp Server online
- Changing the listening port in httpd.conf to 8080 and configuring Skype to accept 80 and 443 ports
Could it be that some firefox extensions are blocking php-execution?
All I get is the php code exactly like I wrote it.
回答1:
You're trying to execute PHP in an ".html" file. You have to edit the PHP handler in the apache config to make it process whatever file extension you want it to. Look for "AddType application/x-httpd-php .php" in your Apache configuration file (somewhere like 'wamp/apache/conf/httpd.conf') then just add " .html" after ".php". The line should look like this now:
AddType application/x-httpd-php .php .html
PHP should now execute any code it finds in files with ".php" and ".html" extensions.
Edit: Or as someone suggested above, just rename your file "sample.php" and it'll be processed.
回答2:
No extensions can interfere with execution of php because it is executed at the server end, not the client end.
The php code is not executed because your file's extension is html and the WAMP server does not process .html
files.
Change the extension to sample.php and then it will work
回答3:
It might help somebody. Changing the tags from
<?
to
<?php
did the trick for me on my WAMP server.
回答4:
If you're seeing literally the string
<?php phpinfo(); ?>
Open the httpd.conf file and uncomment the line
LoadModule php5_module "C:/PROGRA~1/BITNAM~1/php/php5apache2_2.dll"
Also, make sure the filename ends with .php exactly. If windows adds a .txt or other crap when you save the file to the end, apache will not know to have php process it.
回答5:
restart all services and make sure that WAMP server icon is green if it is not then restart wamp server or re-installed it.Then check for localhost.
回答6:
I got here by google for the same symtoms.
In my case, it was just the Windows Explorer wich was hiding file extensions.
A good trap for casual users of Windows, like me.
So instead of having my file named index.php, I had actually index.php.txt.
I fixed the extension display by using this procedure : http://kb.winzip.com/kb/entry/26/
The clue was : I had no IDE icon on my php file.
I don't know if my answer really helps, 5 years after the initial question...
回答7:
Yeah, I too faced the same problem. I solved it by changing the file extensions generally, we save the file with ".php" extension but the computer may get stored in the ".php.txt" extension. So change it by clicking on "view" which is present at the top toolbar of file manager and then mark select to the checkbox "File New Extension", by doing this it will show different extensions to your stored files and accordingly change the extension.
hope, it might solved your problem.
来源:https://stackoverflow.com/questions/10600564/wamp-server-isnt-executing-php-code