Problem parsing html as php since setting php-fpm instead of mod_php

rembem

Verified User
Joined
Nov 21, 2018
Messages
7
On my VPS in Custombuild I changed php1_release from mod_php to php-fpm, version 5.6.

I have some sites where the following 2 lines in htaccess were working perfectly to get html parsed as php, when I had mod_php:

Code:
AddHandler application/x-httpd-php .htm .html
AddType application/x-httpd-php .htm .html

Since I switched to php-fpm, this is not working anymore, pages are getting downloaded.
After googling around, I tried lots of variations, for example:

Code:
AddHandler application/x-httpd-php56 .html .htm
AddType application/x-httpd-php56 .html .htm

Which has the same problem.
And:

Code:
<FilesMatch "\.(inc|php|phtml|phps|php56|htm|html)$">
    AddHandler "proxy:unix:/usr/local/php56/sockets/*myusername*.sock|fcgi://localhost" .inc .php .phtml .php56 .html .htm
</FilesMatch>

Which gives an Access denied.

Does somebody know how to get this working with php-fpm?

Thanks.
 
Your 3rd one looks fine, but you're missing html in |LIMIT_EXTENSIONS| (custom php-fpm config) :)
 
Thanks, but where/how do I change that? Sorry never done this before.

Do I directly change this file?
/usr/local/directadmin/data/users/*username*/php/php-fpm56.conf

I also see this conf file in DA under custom httpd configurations > username
"PHP-FPM config customization for *username* php-fpm 5.6"

But I dont understand how to change this setting. Could you explain how to do this, please?
 
For anyone trying to do the same, I managed to get this working with some trial and error by doing the following:

- In Direct Admin > Custom HTTPD Configurations, klik on the php config file behind the user name. (in my case php-fpm 5.6)
- In the local/user Custom 1 field (in my case php-fpm 5.6 |CUSTOM1|), enter the following:

Code:
|?LIMIT_EXTENSIONS=`LIMIT_EXTENSIONS` .htm .html|

- After saving, the security.limit_extensions value is changed in the file below it, and there should be no errors.

- Not sure if necessary, but then I did a 'build rewrite_confs' with the button below the Custom HTTPD Configurations page.

Then, in .htaccess, I added:


Code:
<FilesMatch "\.(inc|php|phtml|phps|php56|html|htm)$">
    AddHandler "proxy:unix:/usr/local/php56/sockets/*username*.sock|fcgi://localhost" .inc .php .phtml .php56 .html .htm
</FilesMatch>


- replace the *username* in the handler url above with the username. Or look the url up in the custom httpd.conf file for the user, via:
Custom HTTPD Configurations > click on the domain

Note: It would be very helpful if these kind of things would be documented somewhere. The way these 'tokens' work and the line in CUSTOM1 I found somewhere on this forum.
 
Hi
above giving "access denied"?

Yes you fix it by changing the little known ''security.limit_extensions' in php-fpm doing this. You will probably already know the well documented mechanism of changing apache to AddHandler/AddType I will not go into that here.

  • 1. YOU MUST find out where php-fpm/conf is in your set up. I did it by doing this
# grep -rnw '/etc/' -e 'security.limit_extensions'

  • 2. I got this back
'/etc/php-fpm.d/www.conf:387:;security.limit_extensions = .php .php3 .php4 .php5 .php7'
  • 3. go to this file, edit it and MAKE SURE YOU REALISE IT IS COMMENTED OUT
EG: change it from ';security.limit_extensions = .php .php3 .php4 .php5 .php7' <- NB: note the ";" - this line is actually DISABLED by default - and you do not need all the nonsense extensions, in fact they are probably dangerous.. change it to 'security.limit_extensions = .php .htm' <- note the semi colon is now removed. then restart apache/(or nginx) and restart php-fpm # service php-fpm restart # service httpd restart
 
For anyone trying to do the same, I managed to get this working with some trial and error by doing the following:

- In Direct Admin > Custom HTTPD Configurations, klik on the php config file behind the user name. (in my case php-fpm 5.6)
- In the local/user Custom 1 field (in my case php-fpm 5.6 |CUSTOM1|), enter the following:

Code:
|?LIMIT_EXTENSIONS=`LIMIT_EXTENSIONS` .htm .html|

- After saving, the security.limit_extensions value is changed in the file below it, and there should be no errors.

- Not sure if necessary, but then I did a 'build rewrite_confs' with the button below the Custom HTTPD Configurations page.

Then, in .htaccess, I added:


Code:
<FilesMatch "\.(inc|php|phtml|phps|php56|html|htm)$">
    AddHandler "proxy:unix:/usr/local/php56/sockets/*username*.sock|fcgi://localhost" .inc .php .phtml .php56 .html .htm
</FilesMatch>


- replace the *username* in the handler url above with the username. Or look the url up in the custom httpd.conf file for the user, via:
Custom HTTPD Configurations > click on the domain

Note: It would be very helpful if these kind of things would be documented somewhere. The way these 'tokens' work and the line in CUSTOM1 I found somewhere on this forum.

This work fior me, thanks.

- In Direct Admin > Custom HTTPD Configurations, click on php-fpm xx behind the user name. (in my case php-fpm 7.4)
- In the php-fpm xx |CUSTOM1| field, enter the following:
Code:
|?LIMIT_EXTENSIONS=`LIMIT_EXTENSIONS` .htm .html|

Then, in .htaccess, I added:
Code:
<FilesMatch "\.(html|htm)$">
    AddHandler "proxy:unix:/usr/local/php56/sockets/*username*.sock|fcgi://localhost" .html .htm
</FilesMatch>
(I add only the .htm and .html because .php .inc ... are already add by httpd.conf of the user)
 
Back
Top