Hestia CP + Nginx + Php-fpm - php code execution in html

Andy Wits Blog

Hestia CP + Nginx + Php-fpm - php code execution in html

Of course, it is not clear why and who needs it, but it happens that in static html pages you need to execute php code (for example, I had to face such a task).

By default, this function does not work in the Hestia CP + Nginx + Php-fpm panel.

Solution.

You need to edit the standard nginx php-fpm templates. To do this, go to the templates folder and make copies, for example, of the default template:

cd /usr/local/hestia/data/templates/web/nginx/php-fpm
cp default.tpl default-html2php.tpl
cp default.stpl default-html2php.stpl

then we find the block where php is described and add html (or change):

              location ~ [^/]\.php|html(/|$) {
                        try_files $uri =404;
                        include /etc/nginx/fastcgi_params;
                        fastcgi_index index.html;

Then in the Hestia panel we switch the Nginx config (by clicking the Advanced Options button and then Web Template NGINX)

Here the site will most likely stop opening at all, it will write Access Denied and in the logs [domain].access.log we will see the code 403. But in the logs [domain].error.log an error will appear like this:

([domain] - your site domain)

FastCGI sent in stderr: "Access to the script 'index.html' has been denied (see security.limit_extension

This is already more informative. You can fix it like this:

Edit

nano /etc/php/8.2/fpm/pool.d/[domain].com.conf

let's add a line:

security.limit_extensions = .php .html

restart php-fpm

/etc/init.d/php8.2-fpm restart

(instead of 8.2 use your version of php)

! I do not recommend editing any common configs, for security

Published on Aug 22 2023 at 12:00 am
Time to read 1 minute(s)
Categories None

Contact me on