Multi php-fpm (no apache) suggestions

Post Reply
Komisar
Posts: 4
Joined: Sun Oct 22, 2023 3:29 pm

Problem: Multi PHP works only with Nginx + Apache2 config. Apache2 is sometimes an unnecessary memory consumer that makes DDoS attacks be much easier then configured php-fpm. Multi-php for no apache config would be a good benefit of myVesta vs other forks.

One of the well known problems is the $pool variable (func/domain.sh) that contans wrong path in case multiple php versions installed.

Possible concepts:
1. Along with Web Template and Backend Template (mainly unix socket vs tcp socket vs no-php) there could be third field - PHP version. It could be filled the same way as v-list-sys-services correctly lists all FPMs. This concept requires changes in backend scripts and web.

2. Lets make standard of naming backend templates in data/templates/web/php-fpm. I suggest something like PHP-8.3-socket. Then the v-change-web-domain-backend-tpl may be changed to parse the name of the template and extract the required PHP version:

Code: Select all

echo 'PHP-8.3-socket' | cut -d'-' -f2
I suggest replacing $pool usage with something like this:

Code: Select all

# Deleting backend
#rm -f $pool/$backend_type.conf
find /etc/php -name "$backend_type.conf" -delete
and later avoid using $pool again:

Code: Select all

# Changing backend config
cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
    sed -e "s|%backend_port%|$backend_port|" \
        -e "s|%user%|$user|g"\
        -e "s|%domain%|$domain|g"\
        -e "s|%domain_idn%|$domain_idn|"\
        -e "s|%backend%|$backend_type|g" > /etc/php/$phpversion/fpm/pool.d/$backend_type.conf
This second concept skips any changes to web frontend. Also install php version and remove php version scripts would be appreciated (that will add necessary configs).

As for unix socket, I suggest standard naming like
[%backend%]
listen = /var/run/php/83-%backend%.sock
to avoid collisions. And also fpm backends restart code should be revised, either restarting all of them, or only necessary versions.

I'm trying to make the second case on my server just now. I'm not as good in linux script coding to make it correctly handling no-php (that does not contain php version in its name) etc, but I am sure I will be able to finish it for all php unix socket templates.

P.S. unfortunately, Backend Template field has names cut before first dot, I believe there should be last dot, e.g. strrpos instead of strpos.
Post Reply