Applicable to:
- Plesk for Linux
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:
For Plesk Obsidian and Onyx 17.5.3 Update 32 and newer.
- 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.
For Plesk versions earlier than Onyx 17.5.3 Update 32.Connect to the server using SSH.
Create the file
/var/www/vhosts/system/example.com/conf/php.ini
.Open the created file in a text editor and add the following lines:
CONFIG_TEXT: [php-fpm-pool-settings]
security.limit_extensions = .php .phar .html .incIn Plesk, go to Domains > example.com > PHP Settings and click OK to update PHP-FPM pool settings.
- 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:
CONFIG_TEXT: <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>
CONFIG_TEXT: <Directory /var/www/vhosts/example.com/httpdocs>
<Files ~ \.(htm|html)$>
SetHandler None
AddHandler php-script .html .htm
Options +ExecCGI
allow from all
</Files>
</Directory>
CONFIG_TEXT: <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>
CONFIG_TEXT: <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.
Comments
2 comments
on Plesk Obsidian Version 18.0.52 Update #3, nginx (proxy mode) + apache
configured as above:
in PHP settings
in additional apache settings:
recieving "access denied" in browser.
If "Sethandler ..." is commented out - page is loaded, but PHP not parsed.
i have found what was the problem - it was my mistake: i have configured a subdomain, PHP settings
but path for socket-file php-fpm.sock was from main domain
Please sign in to leave a comment.