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 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:
CONFIG_TEXT: [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 .inc -
In Plesk, go to Domains > example.com > PHP Settings and click OK to update PHP-FPM pool settings.
-
-
-
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: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>For PHP handler set as CGI: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>For PHP handler set as FastCGI: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>For PHP handler set as FPM: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 KB article #213413649.
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
19 comments
The php.ini file is located in /var/www/vhosts/system/example.com/etc so should there be a php.ini in /conf beside the httpd.conf, I am a little annoyed ;-)
Hello @Manfred, thank you for notice. The article was updated.
Additionally, since update 32 of Plesk 17.5 it is possible to apply solution via Plesk GUI
Hi Sir,
Am unable to use php tags inside a html page in plesk server.
Below is my server config:
Apache 2.4.6
php 7.0.30
Plese guide me how to resolve the issue.
Hi @Sangeetha Kannaiyan!
Let me know, which version of Plesk is installed?
It may be checked by the command "plesk -v" or at Plesk Panel home page.
Have you tried to instructions from this article?
It seems that since approximately February 2019 the method described for PHP-FPM no longer works. Tested on different installations all showing the same result:
AH01071: Got error 'Access to the script '/var/www/vhosts/<subsription>/httpdocs/<filename>.html' has been denied (see security.limit_extensions)\n'
Adding "security.limit_extensions = .php .html" or "security.limit_extensions =" and restarting PHP-FPM services and web server services does not make any difference. Script access is always denied.
Hi @Peter Debik,
Thank you for the input!
I have used CentOS 7 + Plesk Onyx 17.8 Update #44 for testing this behavior on my side, and it seemed to be working fine, however I used only `<?php phpinfo(); ?>` in my index.html, not sure whether or not this is relevant.
I did the following changes in order to make it work:
1. I used PHP 7.2 FPM Served by Apache AND Served by NGINX (I tested both).
2. I added the following lines to 'Additional configuration directives' at Domains > example.com > PHP Settings :
CONFIG_TEXT: [php-fpm-pool-settings]
security.limit_extensions = .php .phar .html .inc
3. I added the following lines to Additional directives for HTTP and Additional directives for HTTPS:
CONFIG_TEXT: <IfModule mod_proxy_fcgi.c>
<Files ~ .(?i:inc|html|htm)$>
SetHandler proxy:unix:///var/www/vhosts/system/example.com/php-fpm.sock|fcgi://127.0.0.1:9000
</Files>
</IfModule>
After that, I was able to open index.html and see PHP info:
So it seemed like the issue is somewhere in the middle, perhaps some customization in PHP-FPM on a global level or perhaps some issues with nginx config.
Thank you for this detailed explanation. I have tested again and at first came to the same ("it does not work") conclusion as before. Then I noticed your extra line in the configuration settings
[php-fpm-pool-settings]
This is definitely worth to mention in the article, because without this entry, the "security.limit_extensions" is placed into the "php.ini custom configuration directives" section of the domain's configuration file like
php_value[security.limit_extensions] = .php .phar .html .inc
where it does not have any effect. However, when preceded by the [php-fpm-pool-settings] line, it is placed at the end of the "Following directives define pool configuration" section as
security.limit_extensions = .php .phar .html .inc
where it has the desired effect. With the extra "[php-fpm-pool-settings]" line, the configuration works as it did before.
Hi @Peter Debik!
I am so glad to hear that this is sorted out.
Actually, this information was there in the article under step '2', however the point itself was not explained and contains a misleading note regarding short_open_tag.
I now made the section as clear as I could. I hope everything is fine now :)
Hello,
i made so:
php-fpm-pool-settings]
security.limit_extensions = .php .phar .html .inc
and
<IfModule mod_proxy_fcgi.c>
<Files ~ .(?i:inc|html|htm)$>
SetHandler proxy:unix:///var/www/vhosts/system/example.com/php-fpm.sock|fcgi://127.0.0.1:9000
</Files>
</IfModule>
It works great! HTML now processes with PHP handler!
BUT next BIG bug - i lost custom error pages! I get only short - File not found - http://prntscr.com/my9bhe and thats all!
I tried to add to doamins apache setting and to .htaccess
ErrorDocument 404 /404.php
ErrorDocument 403 /404.php
No reaction.
Custom errors also do not works.
I even do not know whow gererates this massage to change it.
My site do not work, because it uses 404 to process files.
Please tell me how to change them?
Thanks!
PS
i found the the problms is more then 2 years and till now it was not fixed?
https://talk.plesk.com/threads/custom-error-documents-not-working-when-php-run-as-a-fpm-application.337376/
Hello @Michael,
Indeed, the issue is not fixed and for now there is no ETA.
The priority was given to other bugs and new features.
In case, I will get additional information, I will let you know.
Thanks, i'll be waiting.
Error are the one of the most importang thing is SEO and websitebuilding.
Hello @Michael,
Currently, it is expected to have this bug solved in next Plesk major release, stay tuned for the change log.
We want Php code in .htm and .html files to be executable on all domains. We have over 200 domains and editing the configuration for each domain from Plesk will take too long.
We managed to solve the problem by creating a custom configuration file in /etc/httpd/conf.d folder with the contents: AddHandler php-script .html .htm. After that Php code in htm and html files on all domains was being executed.
Will the custom configuration file be overwritten by future Plesk updates. Is this a correct approach to solving the problem ?.
Hello @Nadir Latif!
Such changes might be re-written by the updates of the Apache packages shipped by Plesk. And all in all, applying such configuration on the server level is not a good approach.
It is recommended to create a custom template for the domains using our article and documentation:
https://support.plesk.com/hc/en-us/articles/213413649
https://docs.plesk.com/en-US/onyx/advanced-administration-guide-linux/virtual-hosts-configuration/changing-virtual-hosts-settings-using-configuration-templates.68693/
After enabling the configuration in Apache, the PHP execution for html files worked flawlessly. However, Web Statistics for that domain stopped working.
https://foo.bar/plesk-stat/webstat-ssl/ when accessed shows "File not found."
How do we exclude the effect of those directives on this path?
Hello Ninad Gupte
Thank you for bringing out attention to that.
The article has been modified and only files within "httpdocs" directory are affected now. Web statistic page works fine in this way.
I wonder if something has changed with this solution. We're testing on Plesk version 18.0.21, and find that this doesn't work. Seeing 500 errors on the page and "End of script output before headers: cgi_wrapper" in the error log, running as FastCGI/Apache. I did have to edit the directives a bit compared to what's posted above as there were mismatched tags in the example, but even after that the error exists. Anyone know if something is different for this Plesk version?
Bill Haenel this article is applicable to the Plesk Obsidian too. Regarding the error, consider submitting a support request, as additional details will be required to assist you.
https://support.plesk.com/hc/en-us/articles/213608509-How-to-submit-a-request-to-Plesk-support-
Please sign in to leave a comment.