0

I'm having laravel 5.1 run on Nginx local server on CentOS 6.7. Is it possible to pass environment variables set in /etc/environment directly to laravel? I tried but it does not work.

However, if I include the line "fastcgi_param LARAVEL_ENV local;" in my nginx configuration, it works by using getenv('varName') in laravel. This is passed as server environment variable, which is not what I want.

Is it possible to get the environment variable directly from Linux using getenv(), without using fastcgi_param in Nginx?

Return-1
  • 2,329
  • 3
  • 21
  • 56
AlexZai
  • 224
  • 4
  • 11

2 Answers2

0

Laravel 5.1 uses the dotenv package by vlucas (https://github.com/vlucas/phpdotenv) to manage it's environment variables along with a caching layer to mitigate the loading implications associated with the package.

phpdotenv is made for development environments, and generally should not be used in production. In production, the actual environment variables should be set so that there is no overhead of loading the .env file on each request. This can be achieved via an automated deployment process with tools like Vagrant, chef, or Puppet, or can be set manually with cloud hosts like Pagodabox and Heroku.

I would consider using this before going to the effort of delving into NGINX configuration.

Further information can be found in the laravel documentation:

https://laravel.com/docs/5.1/installation#environment-configuration

Spholt
  • 3,724
  • 1
  • 18
  • 29
0

After googling for quite a long time and over the night, the only way to achieve what I intended is through www.conf in php-fpm directory.

I referred to these links:

Access environment variables Laravel 4

What is www.conf

Community
  • 1
  • 1
AlexZai
  • 224
  • 4
  • 11