AddType application/x-httpd-php .html [英] AddType application/x-httpd-php .html

查看:70
本文介绍了AddType application/x-httpd-php .html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从具有PHP 5的服务器迁移到具有PHP 7的新服务器,并且遇到问题告诉Apache将.html解析为PHP脚本.

I am moving from a server with PHP 5 to a new server with PHP 7, and I am having issues to tell Apache to parse .html as PHP scripts.

在我的.htaccess文件中,该行在使用PHP 5的当前服务器上可以正常工作:

In my .htaccess file I have this line working correctly on my current server with PHP 5:

AddType application/x-httpd-php .html

但是在新服务器上,该指令使所有.html文件都被下载,而不是作为PHP脚本执行.

But on the new server, that directive makes any .html file being downloaded instead than executed as a PHP script.

我知道在当前安装了PHP 5的服务器上,PHP的API配置为"Apache 2.0 Handler",而在这台新服务器上,其配置为"FPM/FastCGI",我想这可能是问题所在吗?如果是这样,我该如何克服它而不必更改该API设置?

I know that on the current server with PHP 5 installed, PHP is configured with API set as "Apache 2.0 Handler" whereas on this new server it is configured as "FPM/FastCGI" and I guess that maybe that's the problem? If so, how can I overcome it without having to change that API setting?

我期待着您的回音.预先感谢您的帮助!

I look forward to hearing from you. Thank you in advance for any help!

推荐答案

经过数小时的研究,我最终阅读了以下页面:

After hours of research, I ended up reading this page:

https://www.digitalocean.com/community/questions/php-fpm-security-limit_extension-issue

我通过在.htaccess中添加以下代码来解决此问题:

And I fixed the problem by adding this code inside .htaccess:

<FilesMatch ".+\.html$">
        SetHandler "proxy:unix:/run/php/php7.0-fpm-[myhostname].sock|fcgi://localhost"
</FilesMatch>

为避免服务器给我访问被拒绝"错误,我不得不将此行放在/etc/php/7.0/fpm/php-fpm.conf中:

And to avoid the server to give me an 'access denied' error I had to put this line inside /etc/php/7.0/fpm/php-fpm.conf:

security.limit_extensions = .php .htm .html .inc .rss .rdf .xhtml

然后使用以下命令重新启动PHP守护程序:

Then restarted PHP daemon with:

service php7.0-fpm restart

现在一切似乎都正常了!我说的很复杂,我认为这是由于PHP配备了FPM/FastCGI API.

Now everything seems to work fine! Quite complex I'd say, and I think that'd due to the fact PHP is configured with the FPM/FastCGI API.

欢迎发表评论和想法!

再次感谢大家.

这篇关于AddType application/x-httpd-php .html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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