html文件中的php代码未执行 [英] php code inside html files not executed

查看:60
本文介绍了html文件中的php代码未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的服务器上,我使用 nginx 和 php5-fpm(不是 Apache).

On my server, I am using nginx with php5-fpm (not Apache).

我的 index.php 文件中的所有 HTML、JavaScript 和 php 代码都运行良好.但是如果我将文件重命名为 index.html,嵌入的 php 代码就不会执行.(所有 HTML 和 JavaScript 代码继续正常工作.)

All the HTML, JavaScript and php code in my index.php file runs fine. But if I rename the file to index.html, the embedded php code doesn't execute. (All the HTML and JavaScript code continue to work fine.)

几个答案建议添加行

AddType 应用程序/x-httpd-php5 .html .htm

.htaccess文件,但是下载安装配置nginx和php5-fpm后,我的服务器上没有.htaccess文件.所以我创建了一个,粘贴了上面的行并将文件与 index.html 一起放在网站的根目录中.我重启了nginx,但是php代码还是不行.(可以肯定的是,我只是将文件扩展名从 html 更改为 php,一切都很完美.)

to the .htaccess file, but after downloading, installing and configuring nginx and php5-fpm, there was no .htaccess file on my server. So I created one, pasted the above line and placed the file in the website's root directory along with index.html. I restarted nginx, but the php code still does not work. (To be absolutely sure, I simply changed the file extension from html to php and everything is perfect.)

当我在浏览器呈现的页面上使用 firebug 时,php 标记和代码似乎不存在.

When I use firebug on the rendered page in my browser, the php tag and code don't appear to be there.

推荐答案

哇,只花了几个小时!最终的解决方案是正确的.

Wow, just spent hours on this!!! The final solution is correct from above.

看来,如果/etc/php5/fpm/pool.d/www.conf"有完整的原始行:security.limit_extensions = .php .php3 .php4 .php5你不能只是添加 .html .js

It appears that if "/etc/php5/fpm/pool.d/www.conf" has the full original line:security.limit_extensions = .php .php3 .php4 .php5 you can not just ADD .html .js

该行内容为:security.limit_extensions = .php .html现在它起作用了!!!

The line reads:security.limit_extensions = .php .html and now it works!!!

这篇关于html文件中的php代码未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆