Hello,
I am trying to set up a deploy for Laravel app on a server. I've decided to go with a symlinks of latest release, so this is how my server dir looks like:
/var/www/html/server/
current -> releases/initial
releases
initial
// this is where the git clone has been done
shared
.env // this is my .env file
To make Laravel search for the correct .env file, I've made some changes to the bootstrap/app.php file:
$app = Application::configure(basePath: dirname(__DIR__))
->withRouting(
...
)
->withMiddleware(function (Middleware $middleware): void {
//
})
->withExceptions(function (Exceptions $exceptions): void {
//
})->create();
if (isset($_SERVER['LARAVEL_PROD']) && $_SERVER['LARAVEL_PROD'] === '1') {
$app->useEnvironmentPath('var/www/html/server/shared/.env');
}
return $app;
I thought it would see the $_SERVER param and try the specified location for .env file, but it throws an error that it can't find the .env in the releases/initial/.env somehow.
In nginx config, there's a fastcgi param: fastcgi_param LARAVEL_PROD "1"; and nginx is reloaded and everything.
What am I doing wrong here? Is it better to specify the APP_ENV_FILE /var/www/html/server/shared/.env;, but I suspect that Laravel won't take this var into account by default