Sunday, May 01, 2016

PHP scripts inside HTML on webserver with FCGId

There are lots of articles how to enable PHP scripts inside .html files using AddType and/or AddHandler directives in the Apache web-server configuration file.

But if you have the hosting with PHP engine is running as FCGId module, all these tutorials will not work or will issued downloading of the binary file instead of opening the HTML content in the web-browser :(

Here is a workaround that works for me, just modify .conf file of your website in the following way:


DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/xyz/public_html>
...
AddType application/x-httpd-php .html
AddHandler fcgid-script .html
FCGIWrapper /home/xyz/fcgi-bin/php5.fcgi .html
...
</Directory>
RemoveHandler .html

The "magic" comes in the last two lines. Enjoy :)