Pretty sure that should work, did you reload php5-fpm? Can't remember if setting the params in fastcgi actually passes it to $_ENV or getenv() but $_SERVER
May 30, 2015
8
Level 7
How to pass ENV vars from NGINX to Laravel?
Hi every one,
I googled a lot this issue, but with no luck.
Basically I have this nginx site configuration:
server {
listen 80;
listen [::]:80;
root /var/www/example.com/api/production/current/public;
index index.php index.html index.htm;
server_name api.example.com www.api.example.com;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV "production";
fastcgi_param DATABASE_NAME "database";
fastcgi_param DATABASE_USER "user";
fastcgi_param DATABASE_PASSWORD "password";
include fastcgi_params;
}
}
And in database.php
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => getenv('DATABASE_NAME'),
'username' => getenv('DATABASE_USER'),
'password' => getenv('DATABASE_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
Obviously I'm getting the environment in start.php
$env = $app->detectEnvironment(function () {
return getenv('APPLICATION_ENV');
});
It seems that NGINX doesn't set the environment variables.
I'm using the latest nginx from the nginx/stable ppa with php5-fpm.
What am I doing wrong here?
Thanks in advance to all your (hopefully) replies :D
Please or to participate in this conversation.