• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question Setting php-fpm to listen to 127.0.0.1:9000 by default on all domains

francescoca

New Pleskian
Server operating system version
AlmaLinux 9.3
Plesk version and microupdate number
18.0.58
I need to set my server so that all domains created from now onwards that are using PHP-FPM will listen to 127.0.0.1:9000 instead of php-fpm.sock, which seems to be the default setting.
There are no existing domains at the moment, so I only care about what's going to be created after applying this setting.

Can someone provide some guidance?
 
There will be no guide, as surely nobody ever attempted such a flawed thing, like ever...

First, if would require lots of manual fiddling in config files and Plesk templates
Second, ALL these domains would need to run on the very same subscription (or else the file system and process permissions will kill you, or rather the futile try to manually adjust the permission on each website you ever create and any file you ever upload via FTP or create with the file manager)
Third, you can no longer use different PHP versions for your sites, you would be stuck with the one and only for all domains

And I'm sure I could continue this list of MAYOR problems you will run into, if you try to do what you want to do, if I just think about it a bit more...
Is there even a reason why you wanna use an IP port (and the very same for all domains!) instead of a socket for PHP-FPM?!?
I can't think of any really, that is why nobody does use that anymore.
 
This is a very particular use case indeed, so I'm aware of the limitations and issues that may arise.
When it comes to the first of your points, I have already set up a way to make all new domains point to what I want (i.e. TCP connection, not unix socket). The only thing that's left is creating the config file for the PHP-FPM pool to have the right listen directive. But I can find no template file or any other model for that.
Any tip on that?
 
An alternative (and considering the downsides that you mention, maybe better) approach to what I want to achieve would be to move the php-fpm.sock to a path that's different from the /var/www/vhosts/system/$pool defined in the prefix directive in /opt/plesk/php/[phpver]/etc/php-fpm.d/[domainname].conf, if there's a way to do that instead
 
To make a PFP-FPM pool listen to a TCP port/socket, instead of a unix socket, you can simply change the "listen" parameter in the /opt/plesk/php/[phpver]/etc/php-fpm.d/[domainname].conf file from "php-fpm.sock" to "9000"

To not mess with Plesk internals (and risk the custom config being overwritten every odd moment) you can also copy one of these /opt/plesk/php/[phpver]/etc/php-fpm.d/[domainname].conf files and make your adjustments in there. (be ware of the $prefix setting...I would disable that in this case)
This will work flawlessly, as long as as least one other domain does use the same PHP version. (if there are none domains left using that PHP, the Plesk panel will shut down the whole PHP-FPM process as it thinks it's no longer used)
 
Sure, thank you, but this is on a per domain basis and knew that already. What I am trying to achieve is one system-wide setting that will, from now on, and for every domain created, use the new listen directive. Or even better, in the same conf file, leave the listen directive as is and set a different $prefix for the unix socket instead.
Is there a template or a script that controls that latter option, like there is one for httpd and one for nginx? I have already tried setting that in Service plans => Unlimited => PHP Settings => Additional directives under the [php-fpm-pool-settings] separator and that won't work, the setting seems to be ignored, or at least I can't find any trace of that in the conf file.
 
You can do that in the file /opt/psa/admin/conf/templates/custom/service/php_over_fpm.php
(copy over from /opt/psa/admin/conf/templates/default/service/php_over_fpm.php)
 
Correct me if I'm wrong, but that will only have effect on where httpd will send its requests (i.e. unix socket or tcp connection), but not customize the path to the socket in the /opt/plesk/php/[phpver]/etc/php-fpm.d/[domainname].conf file. Right?
 
Yes, if you wan't to customize the path of the PHP-FPM unix socket file, then you may be out of luck. (seems to be hardcoded somewhere)

But as you want to use the very same socket config/file for all sites, it would also not make sense to let every domain create this file. (will most likely throw errors anyway)
So you just create a /opt/plesk/php/[phpver]/etc/php-fpm.d/MYCUSTOMCONF.conf file manually and adjust the pool name and the path to the unix socket file to your liking. (or change it to TCP socket)
 
First of all, thank you very much for at least trying to get me some help!

Yes, if you wan't to customize the path of the PHP-FPM unix socket file, then you may be out of luck. (seems to be hardcoded somewhere)
This is what I had first thought, because I can't find any relevant string anywhere by just grep-ing the template folder. I don't know if there are better ways to search, if that's the case, I'm willing to learn. But hope someone proves you (and me) wrong.

But as you want to use the very same socket config/file for all sites, it would also not make sense to let every domain create this file. (will most likely throw errors anyway)
Don't get me wrong, let me make things more clear. I had first asked how to use the same TCP endpoint for every site and get a relevant config file for the php-fpm service (i.e. set the conf file to listen on TCP port 9000), but then, also based on some of the downsides you had pointed out which are indeed something to worry about, I switched to asking how to get a different config file for each domain, which is the default and works flawlessly, but placed in a path that's different from the default, outside of the pool directory.

So you just create a /opt/plesk/php/[phpver]/etc/php-fpm.d/MYCUSTOMCONF.conf file manually and adjust the pool name and the path to the unix socket file to your liking. (or change it to TCP socket)
I have already tried going this route, it does seem to spit out random errors, but maybe that's just me and my config.

To sum it up, I'm still left with trying to change the default socket path to something different from /var/www/vhosts/system/$pool, and define it in the prefix directive in /opt/plesk/php/[phpver]/etc/php-fpm.d/[domainname].conf
 
Back
Top