I am using Laravel 5 with a .env and also a config/database.php file that reads as follows:
'mysql' => array(
'default' => 'mysql',
'driver' => 'mysql',
'unix_socket' => getenv('UNIX_SOCKET'),
'host' => getenv('DB_HOST'),
'database' => getenv('DB_DATABASE'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''),
php artisan migrate
fails when I run it, claiming that the Database is not configured. However, I suspect I am doing something wrong in my config file because when I run php artisan -V
I get this?
>php artisan -V
'mysql' => array(
'default' => 'mysql',
'driver' => 'mysql',
'unix_socket' => getenv('UNIX_SOCKET'),
'host' => getenv('DB_HOST'),
'database' => getenv('DB_DATABASE'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
),Laravel Framework version Lumen (5.1.1) (Laravel Components 5.1.*)
php artisan appears to be just printing out my config file and is ignoring it?
Laravel and Lumen config files need to be structured properly for them to work. Also
getenv()
is not the function you want, instead you needenv()
. The database config needs to be structured like this (just swap out your variables):Here's a the full Lumen database config file for your reference.