Where/How to Add WP_ENV per Virtual Host?

Where should I add env WP_ENV=[SOME_ENV] for each virtual host [what file(s) and block(s)]?

e.g.

Thnx for the help

Definitions such as WP_ENV are generally added in wp-config.php, or if you are using a stack like roots.io then you have specific .env locations for it.

This is not part of EE.

That is partially true. However, when WP_ENV is invoked via php (e.g. wp-config), The envelope varible still has to initiated by the server ( Apache e.g. server-environment-prod.conf example: SetEnv ENVIRONMENT "production" ). To set it in NGINX: it would be: SetEnv ENVIRONMENT "production"

Since ee has a set up the I am having trouble following and to my lack of NGINX knowledge, I am not sure to what file and blocks to put them. Usually in a more basic .conf, everything is in one place and I have no issue in adding the SetENV.

My usage is as follows in my wp-config.env.php file:

<?php

switch ($hostname) {
    case 'dev.somesite.com':
        define('WP_ENV', 'development');
        break;
    
    case 'staging.somesite.com':
        define('WP_ENV', 'staging');
        break;
    case 'somesite.com':
    default: 
        define('WP_ENV', 'production');
}

I may have to try creating a .conf-env file and link it to the site .conf but I am concerned what ee update my do to it.

I’m not familiar with setting environment variables in NGINX. Though I did find something here.

However, if you want NGINX to call a separate set of files, and point to a separate database depending on the environment, I would suggest setting each up as a separate EE site. aka…

ee site create dev.somesite.com

ee site create staging.somesite.com

ee site create somesite.com

You can always add custom .conf files to each site here: /var/www/somesite.com/conf/nginx/ - any file in that folder which ends with .conf will be included in your NGINX config file for that site/vhost.

I hope that helps.

Sorry, but that goes against the use of a git/continuous integration setup.

We set up one server to catch all the “development” sub-domains and the WP_ENV directs to the correct database. This allows for a multiple git branches on one file system and a simple SQL script to migrate changes between databases. We use this setup previously on Apache servers and the last few months on NGINx. The usual way I add the SetEnv ENVIRONMENT "production" breaks (restart fails) on ee but not on other NGINx setups.

@rahul286 Some help for the correct implementation of SetEnv on ee would be greatly appreciated - (We’re revisiting ee and really like the fast setup and options it uses!)