How to configure Apache to process PHP code inside an .html file on a Plesk server

Follow

Comments

25 comments

  • Avatar
    Manfred BECK

    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 ;-)

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    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

    0
    Comment actions Permalink
  • Avatar
    Sangeetha Kannaiyan (Edited )

    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.

     

     

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    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?  

    0
    Comment actions Permalink
  • Avatar
    Peter Debik

    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.

     

    0
    Comment actions Permalink
  • Avatar
    Alexandr Redikultsev

    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.

    0
    Comment actions Permalink
  • Avatar
    Peter Debik

    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.

    0
    Comment actions Permalink
  • Avatar
    Alexandr Redikultsev

    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 :)

    0
    Comment actions Permalink
  • Avatar
    Michael M. (Edited )

    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!

    0
    Comment actions Permalink
  • Avatar
    Michael M.

    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/

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    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.

     

    0
    Comment actions Permalink
  • Avatar
    Michael M.

    Thanks, i'll be waiting.

    Error are the one of the most importang thing is SEO and websitebuilding.

     

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov (Edited )

    Hello @Michael,

    Currently, it is expected to have this bug solved in next Plesk major release, stay tuned for the change log.

     

    0
    Comment actions Permalink
  • Avatar
    Nadir Latif

    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 ?.

    0
    Comment actions Permalink
  • Avatar
    Anna Morozyuk

    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/ 

    0
    Comment actions Permalink
  • Avatar
    Ninad Gupte

    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?

    0
    Comment actions Permalink
  • Avatar
    Alexandr Nikolaenko

    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.

    0
    Comment actions Permalink
  • Avatar
    Bill Haenel

    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?

    0
    Comment actions Permalink
  • Avatar
    Robert Asilbekov

    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-

    0
    Comment actions Permalink
  • Avatar
    Klaus SausW

    Die vorgegebenen Einstellungen funktioniereen nicht.

    Ich habe die Fast-CGI-Variante ausgewählt und im Script lediglich die korrekte Domain eingetragen.

    Ich verwende:

    -1
    Comment actions Permalink
  • Avatar
    Klaus SausW

    Früher konnte man diese Anpassungen einfach unter /etc/httpd/... vornehmen. Klappte sofort nach Apache-Neustart.

    Mit Plesk und Linux geht das nicht mehr, aber Plesk bietet keine Lösung an, die wirklich funktioniert.

    ICH WÜRDE NIE WIEDER EINEN SERVER MIT PLESK EINSETZEN. Das geht ohne besser.

    -1
    Comment actions Permalink
  • Avatar
    Peter Debik

    @Klaus SausW Only saying that something does not work without giving further details, e.g. log entries of error messages, does not really help supporters to provide a solution. It could also be helpful to post comments in English, because most of the experts who can help you don't speak German.

    The solution provided in the article should work, so most likely there is a glitch in your implementation. Please consider to either post your question on talk.plesk.com for assistance by the community or to submit a ticket to Plesk support https://support.plesk.com/hc/en-us/articles/213953025-How-to-get-support-directly-from-Plesk- 

    One issue could be that you picked the FastCGI variant as you say, but PHP is not configured for Apache via FastCGI, but via FPM or maybe Nginx via ...(?). Another issue could be that the // has been placed in a new line in your code, but it should be the same line. Yet another issue could be that the domain was changed in the first occurrence in the code, but not the second, so that the path cannot be accessed. Finally, if you are working on a subdomain an issue could be that a letter in the subdomain name is capitalized, which could break a configuration. But again, these things can only be addressed when you provide details of your specific case, and talk.plesk.com is the place to do that and to get expert advice.

    0
    Comment actions Permalink
  • Avatar
    Klaus SausW

    Danke für Ihre Antwort und Reaktion.

    Ich habe mich EXAKT an Ihre Anleitung gehalten. FastCGI gewählt und den Code bei PHP eingetragen.
    Anschließend den Code unter Apache.. eingetragen. GENAUS SO, wie SIE es beschrieben haben.

    Trotzdem funktoniert es NICHT. Im Logbuch sind keine Fehler zu finden, sondern lediglich die normalen Seitenabrufe im access.log.

    Die Wegseite zeigt beim Aufruf von http://www.ksausw.de/schlabberlaetzchen/archiv.htm den Source der PHP-Anweisung, die auf allen anderen Servern sehr gut funktioniert.

    PHP ist korrekt eingerichtet, denn http://www.ksausw.de/schlabberlaetzchen/archiv.php funktioniert.

    Es ist also eindeutig ein Fehler im Plesk, das diesen Handle nicht korrekt an den Apache übergibt.

    0
    Comment actions Permalink
  • Avatar
    Peter Debik

    Sorry to hear that it doesn't work for you as expected. Please, again, if you could post in English it would enable Plesk staff to respond to your comments. I am not Plesk, but a user.

    From your screenshots it seems that there are PHP-FPM settings while you are using the FastCGI interface, not FPM. There could also be a wrong directory path, and according to the source code of your site you are using short open tags in PHP, which could maybe collide with the different handler. Maybe changing the source code to <?php tags instead of <? fixes the issue? Just a guess.

    I can only say that opening a support ticket with Plesk will sure find you a solution for your individual case.

    0
    Comment actions Permalink
  • Avatar
    Klaus SausW

    @Peter Debik
    Thanks a lot for your answer and interest. But sorry - you are wrong.

    1. As you can see on top of this article, I am using the correct code for FastCGI (not for FPM).
    2. The path is correct
          [root@jengatek httpdocs]# pwd
          /var/www/vhosts/ksausw.de/httpdocs
    3. I choosed "Short tags" and as you can see in my examples: this works using .php as file ending
    4. I do not think, that this is an "individual case" as you mentoined. I am running many servers since 25 years on various OS-systems (Suse, Ubuntu, Centos...) and I never had this problem before. On all those machines it was possible to solve this problem systemwide by adding these handles in the /etc/httpd/ directory.

    ?? Where can I open a support ticket ??

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request