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

<>

This question already has an answer here:

Answers


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

Do not assume your unix_socket which would be different from one to another, try to find it.

First of all, get your unix_socket location.

$ mysql -uroot -p

Enter your mysql password and login your mysql server from command line.

mysql> show variables like '%sock%';
+---------------+---------------------------------------+
| Variable_name | Value                                 |
+---------------+---------------------------------------+
| socket        | /opt/local/var/run/mysql5/mysqld.sock |
+---------------+---------------------------------------+

Your unix_soket could be diffrent.

Then you got 2 solution to solve your issue:

(1) Change your config/database.php

    'mysql' => array(
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'essays',
    'username'  => 'root',
    'password'  => 'root',
    'unix_socket'   => '/opt/local/var/run/mysql5/mysqld.sock', //Your sock got from above
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),

(2) Change your php.ini, find your php.ini file from

<? phpinfo();

You maybe install many php with different version, so please don't assume your php.ini file location, get it from your 'phpinfo';

Change your php.ini:

mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock

mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock

pdo_mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock

Then restart your apache or php-fpm.


Had the same problem, but it's working for me now.

If anybody is still having problems, try this:

  • Make sure your bootstrap/start.php contains your actual hostname, not the name of your virtual host. Enter hostname in the terminal to get your hostname. As it's an array I believe you can enter both your hostname and the name(s) of your virtual host(s).
  • Replace "localhost" with "127.0.0.1".

If you are using XAMPP, the solution is:

'mysql' => array(
        'driver'      => 'mysql',
        'unix_socket' => '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock',
        'host'        => 'localhost'
)

This works for me in Laravel 5.0, change the DB_HOST=127.0.0.1:33060 in .env file.

Others answers don't work...


For Laravel 5.0+ change localhost to 127.0.0.1 in your .env file as well before you go playing around with Unix Sockets etc - this worked for me.

Noobs beware: For anyone using Laravel 5 and using older learning material be aware that there was quite a marked shift in folder structure from previous versions though this seems to be for the better- check out this article https://mattstauffer.co/blog/laravel-5.0-directory-structure-and-namespace


Another solution is to add the port number in the host key. In this case MAMP uses the 8889 by default:

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

If you are using Laravle 5.1.11 version + MAC + MAMPP

you have to add "Unix_socket " in file "yourapp"/app/config/database.php

'mysql' => [
    'driver'    => 'mysql',
    'host'      => env('DB_HOST', 'localhost'),
    'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
    'database'  => env('DB_DATABASE', 'forge'),
    'username'  => env('DB_USERNAME', 'forge'),
    'password'  => env('DB_PASSWORD', ''),
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
    'strict'    => false,
],

Unix_socket param was added to above mysql config drive.


Need Your Help

Where are dependent libraries stored in Heroku?

python django heroku dependencies

I've launched my app on Heroku but need to change one of the files of one the dependent libs that I installed in the requirements.txt file.

jQuery: An Extremely Bizarre Behavior with Arguments

jquery if-statement arguments

[update] My bad.. I didn't look through the codes properly.. I should have spotted such a small mistake.. What a shame.. I want to delete this question now but to no avail... It would be great if