Different port per user pool in php-fpm.conf

gospodinov

Verified User
Joined
Apr 19, 2020
Messages
12
Hello. I need to use use tcp socket instead of standard unix socket for php-fpm.The problem is that I can't find way to have a different tcp port for each user pool.
Is there any way to put UID or POOL ID Or User Number in /usr/local/directadmin/data/templates/custom/php-fpm.conf ?
 
Hello,

You can use PHP in Directadmin templates. This way you could create an algorithm of assigning port to users PHP-FPM bases on their PHP-UID for example. This is a raw idea, I don't have a ready solution for this case.

See

- https://docs.directadmin.com/change...ility-to-tokenize-script-output-to-set-tokens
- https://docs.directadmin.com/direct...un-embedded-scripts-in-the-default-index-html
- https://docs.directadmin.com/other-...s.html#how-to-script-own-logic-on-dns-records

for examples and more details.
 
Thank you. It works. But i receive errors :

sh: which: line 1: syntax error: unexpected end of file
sh: error importing function definition for `which'
sh: which: line 1: syntax error: unexpected end of file
sh: error importing function definition for `which'
sh: which: line 1: syntax error: unexpected end of file
sh: error importing function definition for `which'
sh: which: line 1: syntax error: unexpected end of file
sh: error importing function definition for `which'
sh: which: line 1: syntax error: unexpected end of file
sh: error importing function definition for `which'
 
I got the same errors on one of servers which we support. The errors do not effect anything I believe. There is a bug in DirectAdmin somewhere.

The DirectAdmin staff @smtalk @fln might take a look into it.
 
This is not working in nginx_php.conf .... i even tryed
|$/usr/bin/sh
DONE|
And its not working well .... always conflicts....
Cant put variable into variable for example : $UID = 33000 + $id
 
Never tried it with |$/usr/bin/sh. Are you sure DirectAdmin supports it?
OK, if it works with BASH, what is $id in your example? And where is it populated from?
 
The first file is working - php-fpm.conf
Now i need to put
fastcgi_pass 127.0.0.1:$PHP_PORT;
to nginx_php.conf

this is my try :

Code:
|$/usr/local/bin/php
<?php
$directories = glob('/home/*' , GLOB_ONLYDIR);
$directories = array_map(function($value) {
    return basename($value);
}, $directories);
$key = array_search('|USER|', $directories);
switch("|PHP1_RELEASE|"){
case "56" :
$php_port = 30100 + $key;
break;
case "74" :
$php_port = 31000 + $key;
break;
case "81" :
$php_port = 32000 + $key;
break;
case "82" :
$php_port = 33000 + $key;
break;
default :
$php_port = 34000 + $key;
break;
}
echo "set \$PHP_PORT $php_port;";
?>
DONE|

        |*if HAVE_PHP1_FPM="1"|
                # use fastcgi for all php files
                location ~ \.php$
                {
                        try_files $uri =404;
                        fastcgi_split_path_info ^(.+\.php)(/.+)$;
                        include /etc/nginx/fastcgi_params;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        if ( $skip_cache ~ "^$" ) {
                                set $skip_cache 1;
                        }
                        fastcgi_cache_bypass $skip_cache;
                        fastcgi_no_cache $skip_cache;
                        fastcgi_cache FASTCGICACHE;
                        fastcgi_cache_valid 60m;
                        include /etc/nginx/nginx_limits.conf;

                        if (-f $request_filename)
                        {
                                fastcgi_pass 127.0.0.1:$PHP_PORT;
                        }
                }
                location ~ \.(php53|php54|php55|php56|php70|php71|php72|php73|php74|php80|php81|php82)$
                {
                        deny all;
                }
        |*endif|

And its not working...
I also tried to put the variable directly but also didnt work...
cant put variable iside :
|*if HAVE_PHP1_FPM="1"|
 
I got your code working on my end. Do you use NGINX+PHP-FPM? Without Apache?

p.s. By the way, if you add/rename/remove users, then $key will change too. The mentioned actions do not cause rewriting all other users configs. You might run into conflicts with duplicated IDs in such a case.
 
The code is working but the problem is that : fastcgi_pass 127.0.0.1:$PHP_PORT; does not work. This line should not include variable but ready compiled port number.
About the problem with port changing i have made modifications in php-fmp.conf template so there port numbers also will change.
 
Back
Top