Articles in this section

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

kb: how-to Plesk for Linux ABT: Group A

Applicable to:

  • Plesk for Linux

Question

How to configure Apache to process PHP code inside a .html file?

Answer

  1. Log into Plesk as admin user.
  2. Adjust PHP-FPM configuration for the domain:
    1. 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
    2. 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.

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

Was this article helpful?

Comments

2 comments
Date Votes
  • on Plesk Obsidian Version 18.0.52 Update #3, nginx (proxy mode) + apache

    configured as above:

    in PHP settings

    [php-fpm-pool-settings]
    security.limit_extensions = .php .phar .html .inc

    in additional apache settings:

    <IfModule mod_proxy_fcgi.c>
      <Directory /var/www/vhosts/*******.net/httpdocs/*******.net>
        <Files ~ .(inc|html|htm)$>
          SetHandler proxy:unix:///var/www/vhosts/system/*******.net/php-fpm.sock|fcgi://127.0.0.1:9000
        </Files>
      </Directory>
    </IfModule>

    recieving "access denied" in browser.

    If "Sethandler ..." is commented out - page is loaded, but PHP not parsed.

     

    0
  • i have found what was the problem - it was my mistake: i have configured a subdomain, PHP settings

    [php-fpm-pool-settings]
    security.limit_extensions = .php .phar .html .inc

    but path for socket-file php-fpm.sock was from main domain

    SetHandler "proxy:unix:///var/www/vhosts/system/*******.net/php-fpm.sock|fcgi://127.0.0.1:9000"
    0

Please sign in to leave a comment.