Question
How to configure Apache to process PHP code inside a .html file?
Answer
- Log into Plesk as admin user.
- Adjust PHP-FPM configuration for the domain:
- Go to Domains > example.com > PHP Settings and add the following lines into the field Additional configuration directives:
[php-fpm-pool-settings]
security.limit_extensions = .php .phar .html .inc - Click OK to save the changes.
- Go to Domains > example.com > PHP Settings and add the following lines into the field Additional configuration directives:
- Go to Domains > example.com > Apache & nginx settings and add the following lines into the fields Additional directives for HTTP and Additional directives for HTTPS:
For PHP running as an Apache module:
<IfModule mod_php5.c>
<Directory /var/www/vhosts/example.com/httpdocs>
AddHandler php5-script .php .html .htm
AddType text/html .php .html .htm
</Directory>
</IfModule>
For PHP handler set as CGI:
<Directory /var/www/vhosts/example.com/httpdocs>
<Files ~ .(htm|html)$>
SetHandler None
AddHandler php-script .html .htm
Options +ExecCGI
allow from all
</Files>
</Directory>
For PHP handler set as FastCGI:
<Directory /var/www/vhosts/example.com/httpdocs>
<Files ~ .(htm|html)$>
SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .htm
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .html
Options +ExecCGI
allow from all
</Files>
</Directory>
For PHP handler set as FPM:
<IfModule mod_proxy_fcgi.c>
<Directory /var/www/vhosts/example.com/httpdocs>
<Files ~ .(?i:inc|html|htm)$>
SetHandler proxy:unix:///var/www/vhosts/system/example.com/php-fpm.sock|fcgi://127.0.0.1:9000
</Files>
</Directory>
</IfModule>
If a change is required on a global scale, then the virtual host configuration templates can be adjusted and the sections above put into web server configuration files automatically. For more information, check this article.
Note: If short_open_tag
is used in the code, enable it at example.com > PHP Settings > Common Settings > short_open_tag
Note: Full path has to be provided inside <Directory>
tag. If the location of your files is differ, adjust it accordingly. Or remove strings with <Directory>
</Directory>
tags.