Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Artisan Migrate with MAMP and Unix Socket

I was developing my application originally in Laravel 4.2 but have since decided to move it to the 5.0 version so that it covers a lot more changes and strengths that 5.0 has over 4.2.

I am trying to run my migratiosn however I am getting the error:

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

I looked into this and noticed how it is because I'm running MAMP for my server instead of vagrant and homestead. I'm not knocking the uses of those two but I at this point feel more comfortable with MAMP until it fails me. The reason I know its MAMP is because of needing to declare the unix socket value to be used.

Now on my 4.2 version of my application I have the following:

'mysql' => array(
    'driver'    => 'mysql',
    'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
    'host'      => getenv('DB_HOST'),
    ...
),

With my Laravel 5.0 version I am making use of the .env file for my Environment variables and not sure how I need to do this so that it knows to use the unix socket value.

Cans someone clue me into how I should adopt this into the new version or a better way to add it into the settings so that I don't have to do that?

like image 553
user3732216 Avatar asked Mar 27 '15 16:03

user3732216


3 Answers

In laravel 5.5 the unix_socket changes to DB_SOCKET

inside .env file :

DB_USERNAME=root
DB_PASSWORD=root
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

inside config/database.php:

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
like image 84
Esteban Bautista Avatar answered Nov 08 '22 22:11

Esteban Bautista


though quite old question, but still can help others. so adding answer.

there is even simple solution. add this to ur .env file

DB_HOST=localhost;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock
like image 28
S. M. Ibrahim Lavlu Avatar answered Nov 08 '22 22:11

S. M. Ibrahim Lavlu


Try this:

'mysql' => array(
'driver'    => 'mysql',
'unix_socket'   => getenv('UNIX_SOCKET'),
'host'      => getenv('DB_HOST'),
...
),

In .env add

UNIX_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
like image 23
Vlad Slobodkin Avatar answered Nov 08 '22 21:11

Vlad Slobodkin