Is there a possibility to get some Linux system environment variables and still use the .env variables?
是否有可能获得一些Linux系统环境变量并仍然使用.env变量?
We want to use an auto-generated database password that's set as Linux environment variable but can't get Laravel to find the Linux system environment variables.
我们希望使用一个自动生成的数据库密码,该密码设置为Linux环境变量,但不能让Laravel找到Linux系统环境变量。
3 个解决方案
#1
1
Linux system variables cannot be access through PHP/Apache. You could set a variable in the Apache Vhost of your site via SetEnv and grab it in Laravel.
不能通过PHP/Apache访问Linux系统变量。您可以通过SetEnv在站点的Apache Vhost中设置一个变量,并在Laravel中获取它。
You could do
你可以做
- Apache:
SetEnv DB_Pass dbpassword123
in your Vhost - Apache:在Vhost中SetEnv DB_Pass dbpassword123
- Nginx:
fastcgi_param DB_Pass dbpassword123
- Nginx:fastcgi_param DB_Pass dbpassword123
Example Apache Vhost:
示例Apache Vhost:
<VirtualHost example.com:80>
ServerAdmin root@mpj.local.dev
DocumentRoot /var/www/html
ServerName mpj.local.dev
SetEnv DB_Pass dbpassword123
<Directory /var/www/html>
AllowOverride All
Require all granted
</Directory>
ErrorLog "/var/log/apache2/error_log"
CustomLog "/var/log/apache2/access_log" common
</VirtualHost>
and fetch the variable DB_Pass
in Laravel with
在Laravel中获取变量DB_Pass
$dbPass = env('DB_Pass');
#3
-1
You should use 'env' function.
你应该使用“env”函数。
https://laravel.com/docs/5.2/configuration#environment-configuration
https://laravel.com/docs/5.2/configuration环境配置
#1
1
Linux system variables cannot be access through PHP/Apache. You could set a variable in the Apache Vhost of your site via SetEnv and grab it in Laravel.
不能通过PHP/Apache访问Linux系统变量。您可以通过SetEnv在站点的Apache Vhost中设置一个变量,并在Laravel中获取它。
You could do
你可以做
- Apache:
SetEnv DB_Pass dbpassword123
in your Vhost - Apache:在Vhost中SetEnv DB_Pass dbpassword123
- Nginx:
fastcgi_param DB_Pass dbpassword123
- Nginx:fastcgi_param DB_Pass dbpassword123
Example Apache Vhost:
示例Apache Vhost:
<VirtualHost example.com:80>
ServerAdmin root@mpj.local.dev
DocumentRoot /var/www/html
ServerName mpj.local.dev
SetEnv DB_Pass dbpassword123
<Directory /var/www/html>
AllowOverride All
Require all granted
</Directory>
ErrorLog "/var/log/apache2/error_log"
CustomLog "/var/log/apache2/access_log" common
</VirtualHost>
and fetch the variable DB_Pass
in Laravel with
在Laravel中获取变量DB_Pass
$dbPass = env('DB_Pass');
#2
#3
-1
You should use 'env' function.
你应该使用“env”函数。
https://laravel.com/docs/5.2/configuration#environment-configuration
https://laravel.com/docs/5.2/configuration环境配置