Reputation: 265
Is there a possibility to get some Linux system environment variables and still use the .env variables?
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.
Upvotes: 13
Views: 5525
Reputation: 5174
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.
You could do
SetEnv DB_Pass dbpassword123
in your Vhostfastcgi_param DB_Pass dbpassword123
Example Apache Vhost:
<VirtualHost example.com:80>
ServerAdmin [email protected]
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
$dbPass = env('DB_Pass');
Upvotes: 1
Reputation: 64
You should use 'env' function.
https://laravel.com/docs/5.2/configuration#environment-configuration
Upvotes: 0