I don't think you can change the .env file from within Codeception's configuration. I think you must change it from Laravel itself.
You can change it in /bootstrap/app.php. Just before the last line (return $app;), add a check for your environment. Here's what mine looks like:
// Set browser tests to use separate database
if ( isset($_SERVER['HTTP_HOST'] ) && in_array( $_SERVER['HTTP_HOST'],
['testing.local', 'acceptance.badmintonbible.com'] ) )
{
$app->loadEnvironmentFrom('.env.acceptance');
}
return $app;
As you can see, I am using the domain name (HTTP_HOST) to perform the check. The first one is for testing on my localhost. The second one is for testing on my remote server (which is a lot more fiddly to set up).