问题
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.
In my .htaccess file I have this line working correctly on my current server with PHP 5:
AddType application/x-httpd-php .html
But on the new server, that directive makes any .html file being downloaded instead than executed as a PHP script.
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!
回答1:
After hours of research, I ended up reading this page:
https://www.digitalocean.com/community/questions/php-fpm-security-limit_extension-issue
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>
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
Then restarted PHP daemon with:
service php7.0-fpm restart
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.
Comments and thoughts are welcome!
Thanks again to everyone.
来源:https://stackoverflow.com/questions/57861812/addtype-application-x-httpd-php-html