[BlueOnyx:27098] Re: fpmPort mismatch between vsite and its subdomain - fixed

Michael Stauber mstauber at blueonyx.it
Tue Jul 9 18:14:11 -05 2024


Hi Tomohiro,

>> https://devel.blueonyx.it/trac/changeset/5368/
> 
> I have looked at it a little and am concerned.
> 
> Perhaps the Subdomain file
> /etc/httpd/conf.d/subdomains/site28-host.domain.tld.conf must match
> the /etc/httpd/conf/vhosts/site28 file.
> 
> In virtual_host.pl, free ports are dynamically checked.
> In subdomain-new.pl, unlike virtual_host.pl, it does not do so.

Yes, this is fully intentional. If the subdomain uses PHP-FPM, then we 
HAVE to use the same port number as the Vsite is using for PHP-FPM. 
because we do NOT create a new PHP-FPM pool for each subdomain.

So how do we figure out which PHP-FPM port the Vsite itself is using? 
That information is not stored in CODB. So we parse the PHP-FPM pool 
files until we find the one of the Vsite that the subdomain belongs to:

# Search for the FPM pool file and extract the port number
my $fpmPort = find_fpm_port($subdomain->{'group'});

The subroutine find_fpm_port() finds the pool file in question under 
/etc/php-fpm-*.d/* and uses the subroutine extract_fpm_port() to extract 
the port from it and reports it back.

We then use the reported PHP-FPM port in our Apache configuration of the 
subdomain.

Only *if* no port is reported back ...


if ((!defined($fpmPort)) || ($fpmPort eq '')) {
  [...]
}

... we use a fallback method. Which basically should never trigger to 
begin with.

The only real difference between your code and mine is: You parse the 
Apache VirtualHost files for the port number and I parse the PHP-FPM 
pool files for the same information. In the end both accomplish the same.


-- 
With best regards

Michael Stauber


More information about the Blueonyx mailing list