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!

6
  • Did you restart apache2 after adding that to the configuration? Commented Sep 9, 2019 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! Commented Sep 9, 2019 at 23:35
  • Did you check this Q/A Commented Sep 10, 2019 at 0: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! Commented Sep 10, 2019 at 1: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. Commented Sep 10, 2019 at 6:39

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

You saved me. :) Same problem; your solution worked!
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. ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.