sehummel sehummel - 5 months ago 41
PHP Question

Forge not reading my Laravel 5 environment variables

This should be really easy, but it's not. Here is the default settings for a MySQL database in Laravel 5.

'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],


I ran
php artisan env
on the production server and got
production
. I set my environment variables with the correct keys on Forge. But when I run
artisan
on the production server, I get an error: 'Access denied for user 'forge'@'localhost' (using password: NO)' The reason I think it's saying password: NO is that an empty string is the default for DB_PASSWORD if the environment variable is not set.

I think what is happening is that Forge is not reading my environment variables and is using the defaults specified. If I change the values of my environment variables, I get the same error message, which seems to confirm this. I have restarted the Digital Ocean production server, thinking that would force the server to read the variables. But nada. Do I need to do something else in Forge to get it to read the variables. Jeffrey Way's Laracast doesn't indicate that I need to.

What's going on here?

Answer

Laravel 5 is not yet in beta.

Taylor has already mentioned in a recent podcast that he'll need to make changes to Forge to accommodate Laravel 5 environmental settings.

I think from memory he mentioned the ability to just edit the .env file from Forge.

For now - you should just put all your settings into a .env file in the root of your web server and it will work.

Comments