Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kfirba's avatar
Level 50

php artisan returns SQLSTATE[HY000] [2002] No such file or directory

Hello.

I've recently noticed that I just can't even run php artisan on my local machine without the VM being on.

I run php artisan and I get

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

When I try to deploy my code I just can't deploy it because it always returns that error when I try to deploy it from my git repository.

Why is that happening? I'm just trying to run the normal php artisan without ANY attempt to touch the DB with some command. That's super weird!

0 likes
16 replies
kossa's avatar

Can you paste the content of routes.php I thing you're calling you database with a model

kfirba's avatar
Level 50

@kossa do you mean that I somehow invoke the database in my routes.php file?

Here's the file:

<?php

$r = app('router');

$r->group(['prefix' => 'v1'], function ($r) {

    $r->group(['namespace' => 'Auth'], function ($r) {
        // registration and confirmation routes
        $r->post('users', 'AuthController@register');
        $r->get('confirm/{token}', 'AuthController@confirm');

        // login route
        $r->post('authenticate', 'AuthController@authenticate');

        // password route
        $r->put('users/{user_id}/change-password', 'PasswordController@changePassword');
        $r->post('password/reset', 'PasswordController@postEmail');
        $r->post('password/reset/{token}', 'PasswordController@postReset');
    });

    // user routes
    $r->get('users/{user_id}', 'UsersController@show');

    // profile routes
    $r->put('users/{user_id}/profiles', 'ProfilesController@update');
    $r->get('users/{user_id}/profiles', 'ProfilesController@show');

    // tags routes
    $r->get('tags', 'TagsController@index');
    $r->get('tags/{tag_id}', 'TagsController@show');
    $r->get('users/{user_id}/tags', 'TagsController@usersTags');
    $r->post('tags', 'TagsController@store');
    $r->put('tags/{tag_id}', 'TagsController@update');
    $r->put('users/{user_id}/tags', 'TagsController@subscribe');

    // ... Some more which looks pretty much the same

kossa's avatar

Exactly you should check .env file I'm sure here you access to a database, and something wrong ;)

kfirba's avatar
Level 50

@kossa Hey. I've just checked my routes.php file and even if I comment everything out I get that error.

However, when I try to set the DB connection to SQLITE and create an example database.sqlite file it all works.

I just don't understand why do I need the DB connection just to run php artisan? I don't get it...

bashy's avatar

It does checks on the DB connection/table. This has been like this for years.

kfirba's avatar
Level 50

@bashy

How do you explain that if I start a new laravel project I can run php artisan even without configuring a database?

bashy's avatar

If you want to do commands from your local machine - change the DB_HOST to 192.168.10.10 (for Homestead).

kfirba's avatar
Level 50

@bashy I just want to run the standard php artisan command. I can't even do that.

The route you mentioned isn't making any problems. I tried to comment out my WHOLE routes.php file and then run php artisan and still got that error.

@kossa the link was describing an issue where the user tried to use php artisan migrate which hits the DB and then got the error. In my case even just by typing php artisan I get that error.

bashy's avatar

I can't remember what it is but there's something that uses the DB connection.

texeira's avatar

@kfirba if you using lampp as a local server then you can include 'unix_socket' =>'/opt/lampp/var/mysql/mysql.sock' on you database confguration file or path to mysql socket.

Mubashar's avatar

just go to the config folder and then database.php and 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'database' => env('DB_DATABASE', 'laraveltest2'),//here your database name 'username' => env('DB_USERNAME', 'root'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, ], Actually Laravel need database connection and after that your composer will work. If you install composer globally than it should work.

Please or to participate in this conversation.