user2537792 user2537792 - 12 days ago 8
MySQL Question

Lumen error when using artisan migrate

I'm new to Lumen and when I try to use:

php artisan migrate


I get the following error.

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory


If I change 'localhost' to '127.0.0.1' I get this error:

[PDOException]
SQLSTATE[HY000] [2002] Connection refused


If I use:

php artisan migrate --database=Lumen


I get:

[InvalidArgumentException]
Database [Lumen] not configured.


Here is my .env file

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=Lumen
DB_USERNAME=root
DB_PASSWORD=root


I've read other questions on stack overflow and have tried the solutions i.e. configuring php versions and checking the path to mysql.sock and it's all fine. I am using the full path and my PHP version is correct.

I am using MAMP and have a Database called 'Lumen' (there are no tables at the moment).

Created a migration using terminal:

php artisan make:migration --create=items create_items_table


I am using php artisan serve (server 8000) to view my project, which I can view.

MAMP is on:
apache=80
nginx=80
mysql=3306


I used the same configuration for my Laravel project and that is working fine. But laravel does have a database.php file which has all the details inside of it.

I hope that's enough information, any help would be much appreciated!

Thanks in advance

EDIT: This is my app.php file, the rest is left untouched.

require_once __DIR__.'/../vendor/autoload.php';

Dotenv::load(__DIR__.'/../');


$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);

$app->withFacades();
$app->withEloquent();

Answer

After a lot of fiddling about, I found the answer.

The problem was with MAMP, the pdo socket for mysql was not in the php.ini file and had to be included there.

[Pdo_mysql]
; If mysqlnd is used: Number of cache slots for the internal result set cache
; http://php.net/pdo_mysql.cache_size
pdo_mysql.cache_size = 2000

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket
pdo_mysql.default_socket=

Including that line fixed all my probelems.