PHP in HTML (again, but for 1 site only)

I have some old sites with php code in html files. It worked with Addtype in htaccess before. Here it doesn’t work this way. I read eris advice here - Not work PHP code in HTML files - #4 by eris but I do not need php in html for all my sites on the server, but just for 1 or 2. So I decided to go through local site config. I copied

    <FilesMatch \.php$>
        SetHandler "proxy:unix:/run/php/php8.2-fpm-domain.com.sock|fcgi://localhost"
    </FilesMatch>

changing .php to .htm at /home/user/conf/web/domain.com/apache2.conf
As a result I got Access denied on the whole site :frowning:
What did I do wrong?

You also need to:

1.- Edit php-fpm conf file for your domain. It should be here:
/etc/php/8.2/fpm/pool.d/domain.com.conf

And add at the end of file this directive.
security.limit_extensions = .htm

Save the file and restart php service.
systemctl restart php8.2-fpm

2.- Edit nginx conf files (both, normal and ssl)

/home/YourUser/conf/web/YourDomain/nginx.conf
/home/YourUser/conf/web/YourDomain/nginx.ssl.conf

And remove htm extension from both conf files:

Original:

location ~* ^.+\.(css|htm|html|js|json|xml|[...]

Modified:

location ~* ^.+\.(css|html|js|json|xml|[...]

Restart nginx:

systemctl restart nginx

And as you already modified apache2.conf:

    <FilesMatch \.htm$>
        SetHandler "proxy:unix:/run/php/php8.2-fpm-domain.com.sock|fcgi://localhost"
    </FilesMatch>

It should work fine now.

Note: Once you check whether it works, you would need to create customized php, nginx and apache templates for your domain with all these changes or the conf will be overwritten when rebuilding the web domain.

2 Likes

Thanks a lot, did as you said, created templates, it works fine.
Just one addition, you should add security.limit_extensions = .htm .php otherwise php files will not work (I have both .php and php in .htm).

1 Like

You are welcome.

You said you were using htm so I just included that extension to be used by php-fpm :wink:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.