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

mstnorris's avatar

php artisan route:list PDOException

When I run php artisan route:list from my host machine on one of my projects I get the following error

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

It doesn't occur on another project (also from my host machine)

Both projects handle the command fine while in the VM.

I'm running Mac OS X 10.10 with Homestead.

0 likes
13 replies
elimantara's avatar

This solved my problem:

Find mysql.sock. In my case, I used MAMP, and I found it in /Applications/MAMP/tmp/mysql/mysql.sock Then, add this to your config\database.php:

'mysql' => array(
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
        'database'  => 'database',
        'username'  => 'root',
        'password'  => 'root',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),

Hope that helps

mstnorris's avatar

Thank you, but I don't have MAMP installed. And I have exactly the same set up with another project. I have a feeling that it is a problem in my routes file. I'll report back if I find anything.

bashy's avatar

Using different database settings? The no such file is from it not finding the socket. Maybe you need to put the IP of the VM for the connection details. Or 127.0.0.1:33060

codybuell's avatar

Had the same problem, OSX running Homestead. The solution was to update DB_HOST to the Homestead VM IP address.

nhswebservices's avatar

I had the same issue today and I went back through and added my routes 1 by 1 to my 'routes.php' file. Oddly enough I noticed that when I removed

Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
]);

from my 'routes.php' I could use 'php artisan route:list' just fine. Not sure if this helps explain why this issue is happening though.

Not sure if this helps anybody but I thought I'd throw it out there.

1 like
bashy's avatar

@nhswebservices It's because the Auth controller calls the database stuff... thus creating the need for the database connection.

This error relates directly to the connection of MySQL, not Laravel (in a code sense).

SQLSTATE[HY000] [2002] No such file or directory
2 likes
bestmomo's avatar

The route:list command instanciates the controllers to get the middlewares, so all contructors are called. AuthController needs to read the users table in database. So to use route:list in this case you need a connexion to your database.

2 likes
postitief's avatar

I had this same issue with the homestead vm. My mistake was that I ran the php artisan route:list from my mac command line. But you need to run this from the Homestead commanline.

So first SSH to the homestead VM: homestead ssh Then go to the root of your project an run php artisan route:list

mstnorris's avatar

I can run php artisan make:model and alike absolutely fine, so why not the route:list command?

milton's avatar

Make sure you are using on your terminal window the same PHP version as the Laravel App.

Check it with the "which php" command and you will probably need to load your PHP environment Path (MAMP, etc) in your .bash_profile or .profile file. Then just call it with the "source .profile" command and try again. That will probably solve your issue with you route:list command.

Please or to participate in this conversation.