3

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!

fablau
  • 51
  • 1
  • 4
  • Did you restart apache2 after adding that to the configuration? – Markus Zeller Sep 09 '19 at 22:20
  • Yes, no avail. Also, since it is added to the .htaccess file, Apache restart shouldn't be necessary... thanks for your help though! – fablau Sep 09 '19 at 23:35
  • Did you check this [Q/A](https://stackoverflow.com/q/6295141/5407848) – Accountant م Sep 10 '19 at 00:18
  • Thank you for your suggestion, I just checked all of what suggested there but nothing is working! Any more ideas? I am pretty desperate... tried everything I could think of! – fablau Sep 10 '19 at 01:05
  • When you are using fpm it may also require restarting that. Make sure the libmod-apache2-php is enabled. Can you open PHP files as intended? Try doing this directly in the apache config. Maybe the directive to allow .htaccess files is not set properly. – Markus Zeller Sep 10 '19 at 06:39
  • Thanks, Markus for your suggestion, everything works fine for PHP scripts with .php extension...therefore I guess libmod-apache2-php is configured correctly. – fablau Sep 10 '19 at 13:52

1 Answers1

2

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.

fablau
  • 51
  • 1
  • 4
  • You saved me. :) Same problem; your solution worked! – FoulFoot Oct 14 '19 at 00:38
  • This actually was my same problem. But, I'm wondering if anyone out there thinks that this is even necessary for security, given how difficult they made it. ?? – Jesse Jan 16 '20 at 11:21