I have just finished splitting my Symfony application into multiple apps by following the documentation: https://symfony.com/doc/current/configuration/multiple_kernels.html
At the bottom it says Additionally, you might need to update your web server configuration to set the APP_ID=admin under a different domain.
. How do I do that?
I use Apache on my local machine and my server is using NGINX.
My current local configuration for Apache:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/alexandra/dev/Web/PROJECT/public
<Directory /Users/alexandra/dev/Web/PROJECT/public>
Require all granted
AllowOverride None
DirectoryIndex index.php
Options -Indexes
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
</Directory>
</VirtualHost>
Here's the server configuration for NGINX:
server {
server_name ...
listen 443 ssl;
ssl_certificate ...
ssl_certificate_key ...
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;
root /var/www/PROJECT/public/;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log ...
access_log ...
}
I have to say first that splitting up your application is rarely required. If you think your different applications will require the same bundles/libraries and the same config.yaml
settings, it is not the first thing to come in my mind to split the application like that.
Usually if for example, you need different users for frontend and admin, you can split it up by defining a different UserProvider for a different firewall that listens on everyting on /admin
subpath.
But to answer you question:
There are a few ways, but the easiest I think is by using the SetEnv
apache directive, which is documented here: https://httpd.apache.org/docs/2.4/mod/mod_env.html.
The only requirement is that your webserver MUST have installed the mod_env apache module. Then you can setup your apache configuration using the SetEnv
Directive.
<VirtualHost *:80>
Servername yourdomain.com
//...
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_env.c>
SetEnv APP_ID [the-yourdomain.com-identifier-here]
</IfModule
//...
</VirtualHost>
<VirtualHost *:80>
Servername anotherdomain.com
//...
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_env.c>
SetEnv APP_ID [the-anotherdomain.com-identifier-here]
</IfModule
//...
</VirtualHost>
There are other approaches too, but they require you to customise the Kernel.php
files. Like loading a different .env
file per domain, or changing the APP_ID
variable alltogether to suffix the domain. There are probably many more approaches, but I think the SetEnv
directive is the best approach.