PHP7.4 , Php-FPM, and Multiple Vhosts_Sites

I am having a very difficult time setting up vhosts aka multiple tld, multiple domains under the same VM/Static IP under Freebsd for an app I am currently working.

The CORE site/ site1 works no problem, and is accessible (can login/front gui works, etc) ...

Problem is with secondary, third, fourth domain/ || /usr/local/www/site1 /usr/local/www/site2 /usr/local/www/site3 /usr/local/www/site4


All the sites have PHP 7.4 and I am using php-fpm.

I did not create multiple pools for php-fpm YET or users to keep it simple and get this working properly with the default setup.

For the PHP-FPM I added 2 different
/usr/local/etc/apache24/module.d/010-php_fpm.conf
&
/usr/local/etc/apache24/module.d/020-php_fpm.conf

AND the module.d config rule standard

Code:
<IfModule proxy_fcgi_module>
#
#
#Allow php to handle Multiviews
#
DirectoryIndex index.php
#
ProxyRequests Off
#
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/var/run/php-fpm.sock|fcgi://localhost/usr/local/www/www.site1.com/public
#
<FilesMatch "\.(php|phps|phar|html|inc)$">
        SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/"
#SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/usr/local/www/www.site1.com/public"
</FilesMatch>
#
     ErrorLog /var/log/httpd-error.log
     Loglevel debug
#
#
</IfModule>


I am putting the Vhosts files in
/usr/local/etc/apache24/Includes/sites1.conf
||
/usr/local/etc/apache24/Includes/sites2.conf ...

Code:
<VirtualHost *:80>
  DocumentRoot "/usr/local/www/www.site1.com/public"
  DirectoryIndex index.php index.html index index.htm
  ServerName www.site1.com
  ServerAlias www.site1.com
  ErrorLog /var/log/httpd-error.log
  LogLevel warn
<Directory "/usr/local/www/www.site1.com/public">
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Require all granted
</Directory>
</VirtualHost>

and

apachectl -M

Code:
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_prefork_module (shared)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 proxy_module (shared)
 proxy_fcgi_module (shared)
 ssl_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 vhost_alias_module (shared)
 dir_module (shared)
 alias_module (shared)
 rewrite_module (shared)

apachectl -S

Code:
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server www.site1.com (/usr/local/etc/apache24/Includes/www.site1.conf:1)
         port 80 namevhost www.site1.com (/usr/local/etc/apache24/Includes/www.site1.conf:1)
                 alias site1.com
         port 80 namevhost www.site2.com (/usr/local/etc/apache24/Includes/www.site2.conf:1)
                 alias site2.com
*:443                  is a NameVirtualHost
         default server www.site1.com (/usr/local/etc/apache24/Includes/www.site1-le-ssl.conf:2)
         port 443 namevhost www.site1.com (/usr/local/etc/apache24/Includes/www.site1-le-ssl.conf:2)
                 alias site1.com

Anyone has any guidance or debug instructions to get vhosts properly working... Might be small oversight on my part.

From my end I don't see any issues, I tested creating different php-fpm pools and creating new users for each site but at the end same result....

Site1.com works with other sites/tld site2.com shows site1.com not vhosts of site2.


MY CURRENT SOLUTION:
In a Debian & CentOS (Linux) VM I am able to setup multiple vhosts no problem of above site1, site2, site3 etc.... Matter of fact that's how I have it in my local environment via a Linux Bhyve VM.

Current work around in FreeBSD for me is to have an individual BHYVE for each Dev/Production version of site but that gets expensive in terms of STATIC IPs and VM resources....

Ideal goal is to have like in my linux local VM be able to have site1....site5 in (1) FreeBSD VM as most are variants and use same dependencies/requirements php, node, etc...
 
Are those sites actually entirely different/separate sites?
The "usual" way of doing this is to have one jail per website. That jail runs everything required for the site to work (nginx, php, nodejs, ...) and then having a reverse proxy in front of those jails. All of this can run on one single FreeBSD host with a single IP address.

I outlined the scenario here: https://blog.insane.engineer/post/freebsd_simple_hosting/

Using jails keeps everything neatly separated (both for administration & security purposes) and the overhead is minimal.
This approach is also very flexible. You can easily add more sites/servers without problems. You can also easily have a production & development environment this way without running into the risk of interference. Furthermore, you can easily restrict resources of a particular website by just limiting the corresponding jail's resources (eg. number of CPUs, maximum RAM size, ...) without dealing with pesky software specific configurations.
 
Back
Top