Setting up Laravel on a Mac php artisan migrate error: No such file or directory

Tim Truston picture Tim Truston · Oct 20, 2013 · Viewed 77.7k times · Source
  1. Pulled a perfectly working laravel project from a git into a mac running MAMP. Project ran perfectly on a linux machine.
  2. composer install
  3. php artisan migrate, got the following error:

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

NB: php -v is 5.5 and mysql -v is 5.5 from the terminal Here is part of my config/database.php

    'mysql' => array(
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'essays',
        'username'  => 'root',
        'password'  => 'root',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),

I tried replacing localhost with 127.0.0.1 with no avail. Kindly help..

Edit: I added these three lines in my php.ini

mysql.default_socket = /var/run/mysqld/mysqld.sock

mysqli.default_socket = /var/run/mysqld/mysqld.sock

pdo_mysql.default_socket = /var/run/mysqld/mysqld.sock

I also added this symlink:

sudo mkdir /var/mysql
cd /var/mysql && sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

But that didnt solve. I also pulled a fresh new laravel project from git and ran into the same error after composer install then php artisan migrate

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

The mac version is 10.7.4

Answer

keithics picture keithics · Dec 30, 2013

If you are using MAMP be sure to add the unix_socket key with a value of the path that the mysql.sock resides in MAMP.

'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'    => '',
    ),