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

Follow

Comments

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

  • 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

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

     

     

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

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

     

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

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

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

  • 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!

  • 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/

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

     

  • Avatar
    Michael M.

    Thanks, i'll be waiting.

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

     

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

     

Please sign in to leave a comment.

Have more questions? Submit a request