简体   繁体   English

Wamp 服务器不执行 php 代码

[英]Wamp Server isn't executing php code

My php code is not executed when I access the root directory with当我访问根目录时,我的 php 代码没有执行

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多次重新启动所有服务,包括将 Wamp Server 联机
  • Changing the listening port in httpd.conf to 8080 and configuring Skype to accept 80 and 443 ports将httpd.conf中的监听端口改为8080,并配置Skype接受80和443端口

Could it be that some firefox extensions are blocking php-execution?可能是某些 Firefox 扩展阻止了 php 执行?

All I get is the php code exactly like I wrote it.我得到的只是和我写的完全一样的 php 代码。

No extensions can interfere with execution of php because it is executed at the server end, not the client end.没有扩展可以干扰 php 的执行,因为它是在服务器端执行的,而不是客户端。

The php code is not executed because your file's extension is html and the WAMP server does not process .html files. php 代码未执行,因为您的文件的扩展名是 html 并且 WAMP 服务器不处理.html文件。

Change the extension to sample.将扩展名更改为示例。 php and then it will work php然后它会工作

You're trying to execute PHP in an ".html" file.您正在尝试在“.html”文件中执行 PHP。 You have to edit the PHP handler in the apache config to make it process whatever file extension you want it to.您必须在 apache 配置中编辑 PHP 处理程序,以使其处理您想要的任何文件扩展名。 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".在 Apache 配置文件中查找“AddType application/x-httpd-php .php”(例如“wamp/apache/conf/httpd.conf”),然后在“.php”之后添加“.html”。 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. PHP 现在应该执行它在带有“.php”和“.html”扩展名的文件中找到的任何代码。

Edit: Or as someone suggested above, just rename your file "sample.php" and it'll be processed.编辑:或者正如上面有人建议的那样,只需将您的文件重命名为“sample.php”,它就会被处理。

It might help somebody.它可能会帮助某人。 Changing the tags from更改标签从

<?

to

<?php

did the trick for me on my WAMP server.在我的 WAMP 服务器上帮我解决了这个问题。

If you're seeing literally the string如果你从字面上看到字符串

<?php phpinfo(); ?>

Open the httpd.conf file and uncomment the line打开 httpd.conf 文件并取消注释该行

LoadModule php5_module "C:/PROGRA~1/BITNAM~1/php/php5apache2_2.dll"

Also, make sure the filename ends with .php exactly.另外,请确保文件名完全以 .php 结尾。 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.如果windows在保存文件时添加了.txt或其他废话,apache将不知道让php处理它。

重新启动所有服务并确保 WAMP 服务器图标为绿色,如果不是,则重新启动 wamp 服务器或重新安装它。然后检查本地主机。

I got here by google for the same symtoms.我通过谷歌来到这里是为了同样的症状。

In my case, it was just the Windows Explorer wich was hiding file extensions.就我而言,它只是隐藏文件扩展名的 Windows 资源管理器。

A good trap for casual users of Windows, like me.对于像我这样的 Windows 临时用户来说,这是一个很好的陷阱。

So instead of having my file named index.php, I had actually index.php.txt.因此,我没有将我的文件命名为 index.php,而是实际上使用了 index.php.txt。

I fixed the extension display by using this procedure : http://kb.winzip.com/kb/entry/26/我使用以下程序修复了扩展显示: http : //kb.winzip.com/kb/entry/26/

The clue was : I had no IDE icon on my php file.线索是:我的 php 文件上没有 IDE 图标。

I don't know if my answer really helps, 5 years after the initial question...我不知道我的回答是否真的有帮助,在最初的问题 5 年后......

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.我一般通过更改文件扩展名来解决它,我们以“.php”扩展名保存文件,但计算机可能会存储在“.php.txt”扩展名中。 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.希望,它可能会解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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