Laravel 5.1 在 Nginx 上获取 Linux 环境变量
Laravel 5.1 on Nginx get Linux environment variables
我在 CentOS 6.7 的 Nginx 本地服务器上 laravel 5.1 运行。
是否可以将 /etc/environment 中设置的环境变量直接传递给 laravel?我试过了,但没有用。
但是,如果我包含该行
"fastcgi_param LARAVEL_ENV local;"
在我的 nginx 配置中,它通过在 laravel 中使用 getenv('varName') 来工作。这是作为服务器环境变量传递的,这不是我想要的。
是否可以使用 getenv() 直接从 Linux 获取环境变量,而无需在 Nginx 中使用 fastcgi_param?
Laravel 5.1 使用 vlucas
(https://github.com/vlucas/phpdotenv) 的 dotenv
包来管理它的环境变量以及缓存层以减轻与包相关的加载影响.
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.
在深入研究 NGINX 配置之前,我会考虑使用它。
可以在 laravel 文档中找到更多信息:
https://laravel.com/docs/5.1/installation#environment-configuration
在谷歌搜索了很长时间和一个晚上之后,实现我想要的唯一方法是通过 php-fpm 目录中的 www.conf。
我参考了这些链接:
Access environment variables Laravel 4
我在 CentOS 6.7 的 Nginx 本地服务器上 laravel 5.1 运行。 是否可以将 /etc/environment 中设置的环境变量直接传递给 laravel?我试过了,但没有用。
但是,如果我包含该行 "fastcgi_param LARAVEL_ENV local;" 在我的 nginx 配置中,它通过在 laravel 中使用 getenv('varName') 来工作。这是作为服务器环境变量传递的,这不是我想要的。
是否可以使用 getenv() 直接从 Linux 获取环境变量,而无需在 Nginx 中使用 fastcgi_param?
Laravel 5.1 使用 vlucas
(https://github.com/vlucas/phpdotenv) 的 dotenv
包来管理它的环境变量以及缓存层以减轻与包相关的加载影响.
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.
在深入研究 NGINX 配置之前,我会考虑使用它。
可以在 laravel 文档中找到更多信息:
https://laravel.com/docs/5.1/installation#environment-configuration
在谷歌搜索了很长时间和一个晚上之后,实现我想要的唯一方法是通过 php-fpm 目录中的 www.conf。
我参考了这些链接:
Access environment variables Laravel 4