PHP Artisan Migrate with MAMP and Unix Socket

I developed my application initially in Laravel 4.2, but since then I decided to port it to version 5.0, so it covers a lot more changes and strengths than 5.0 has more than 4.2.

I try to start myratiosn, but I get an error:

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

I looked at this and noticed how this happens because I am running MAMP for my server instead of vagrants and manors. I do not knock in favor of these two, but at this moment I feel more comfortable with MAMP until he let me down. The reason I know its MAMP is because of the need to declare the value of the unix socket to be used.

Now in my version 4.2 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 version of Laravel 5.0, I use the .env file for my environment variables and don't know how I need to do this so that it knows how to use the unix socket value.

Someone tell me how I should accept this in the new version or the best way to add it to the settings so that I do not need to do this?

+6
source share
4 answers

Try the following:

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

In .env add

 UNIX_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock 
+19
source

although a rather old question, but still may help others. therefore adding an answer.

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

 DB_HOST=localhost;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock 
+3
source

Thanks, help fix the migration problem for me using:

 MAMP PRO 4.2 Laravel 5.5 

inside the .env file:

 DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=<database name> DB_USERNAME=<username - default root> DB_PASSWORD=<password - default root> UNIX_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock 

inside config / database.php:

 'connections' => [ 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', '<database name>'), 'username' => env('DB_USERNAME', '<username - default root>'), 'password' => env('DB_PASSWORD', '<password - default root>'), 'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ], ], 

Also do not forget to add to the application / Providers / AppServiceProviders.php:

 use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); } 
0
source

In laravel 5.5, unix_socket changes to DB_SOCKET

inside the .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', ''), 
0
source

Source: https://habr.com/ru/post/984326/


All Articles