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

标签 linux laravel nginx centos environment

我在 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/

相关文章:

java - 如何在 HDFS Hadoop (Cloudera) java 中创建目录到文件

css - laravel CSS 未加载

nginx lua-resty-http 无路由到主机错误

nginx - php-fpm 不工作 exec、系统、shell_exec,只有 CLI

node.js - 使用 Node.js 和 Nginx 进行负载平衡长轮询请求

C 程序将在 Linux 而不是 Windows 中编译和运行

linux - 向所有容器公开端口,而不仅仅是主机

linux - NS-3 dce 和 iperf3

git - 为什么 sqlite3 不能在我的 homestead/Laravel 设置中工作?

php - 从 laravel 中的时间戳获取日期