gpt4 book ai didi

linux - Laravel 5.1 on Nginx 获取Linux环境变量

转载 作者:太空宇宙 更新时间:2023-11-04 12:28:15 25 4
gpt4 key购买 nike

我在 CentOS 6.7 上的 Nginx 本地服务器上运行 laravel 5.1。是否可以将/etc/environment 中设置的环境变量直接传递给 laravel?我试过了,但没有用。

但是,如果我包含该行“fastcgi_param LARAVEL_ENV 本地;”在我的 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

关于linux - Laravel 5.1 on Nginx 获取Linux环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43999185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com