2

As we have upgrade OS from centos 6.9 to Centos 7 on server. We have installed "Apache/2.4.6" and "PHP 5.6.36 (fpm-fcgi)" on this server. But we are facing problem to execute "PHP Code" in ".html" files. PHP code working fine in ".php file" but not in ".html files". I have ready many blogs but no where mentioned exact solution.

Can you please guide us how we can execute PHP code in .html files.

Note : We are using Apache 2.4, PHP-FPM and MPM_worker on centos 7.

After change below in files "/etc/php-fpm.d/www.conf" and "/etc/httpd/conf.d/php.conf" :

"security.limit_extensions = .php .php3 .php4 .php5 .htm" // in www.conf

and SetHandler "proxy:fcgi://127.0.0.1:9000" // in php.conf

PHP code working in htm files but due to to these changes every html files renders as php. We want only php code render as php not html code render by php.

Your help would be appreciated.

krlzlx
  • 5,752
  • 14
  • 47
  • 55
  • This is a sort of an answer. I found [here](https://stackoverflow.com/questions/22853669/how-to-run-a-php-script-inside-a-html-file) what can be an answer for this, I hope it responds what you whant to know. Read all comments – Ruben Sebastian Jul 16 '18 at 12:58
  • 1
    Try this: https://stackoverflow.com/questions/6295141/server-not-parsing-html-as-php ... not 100% certain I'd recommend it as you're invoking the PHP parser every time an .html file is called but it's your call. – CD001 Jul 16 '18 at 13:00

1 Answers1

0

This is how I configure Apache / PHP-FPM for a virtual host. It's not a public server so I'm only using HTTPS. This is from /etc/httpd/conf.d/ssl.conf:

<VirtualHost _default_:443>
DocumentRoot "/home/myvhost/public_html"
ServerName myvirtualhost.com:443

        <Directory "/home/myvhost/public_html">
                allow from all
                Options FollowSymLinks SymLinksIfOwnerMatch
                Require all granted
                php_admin_value open_basedir /home/myvhost/public_html
        </Directory>

        SuexecUserGroup myvhost myvhost

        ProxyPassMatch ^(/.*\.php)$ fcgi://127.0.0.1:9000/home/myvhost/public_html/$1

        <FilesMatch \.php$>
                # SetHandler application/x-httpd-php
                SetHandler "proxy:fcgi://127.0.0.1:9000"
                SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
        </FilesMatch>

</VirtualHost>

And this is from /etc/php-fpm.d/myvhost.conf (copied from the default PHP-FPM configuration file):

[myvirtualhost.com]
user = myvhost
group = apache

listen = 127.0.0.1:9000

security.limit_extensions = .php

So basically you could just copy the "ProxyPassMatch" line and change php to html and do the same thing with "FilesMatch". You can also modify the regex but I'm not really good at that.