MAMP with Unix Laravel socket

I am working with MAMP on my local development server in my laravel application and I am trying to figure out how I can set up my server securely so I dont need to use the following in the mysql connections database which should only be used when I am on my development server. It works when I add a row to the mysql array, however this is not used if I was on a production server. Any ideas?

'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',

      

.env.development.php

<?php

return [
    'DB_HOST' => '127.0.0.1',
    'DB_USERNAME' => 'root',
    'DB_PASSWORD' => '1234',
    'DB_NAME' => 'mytable'
];

      

app / config / database.php

'connections' => array(

        'mysql' => array(
            'driver'    => 'mysql',
            'host'      => getenv('DB_HOST'),
            'database'  => getenv('DB_NAME'),
            'username'  => getenv('DB_USERNAME'),
            'password'  => getenv('DB_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ),

      

+8


source to share


5 answers


Check environment detection item in bootstrap/start.php

. You must add your machine name to the keyed array local

. (If you don't know the name of your computer, run hostname

in a terminal. If it's something silly, Google how to change it. It's pretty simple.) Then copy and paste the database settings into app/config/local/database.php

. Create the file if it doesn't exist.



+5


source


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



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

      

+12


source


On config/database.php

:

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST'),
            'unix_socket' => env('UNIX_SOCKET'),
            'port' => env('DB_PORT'),
            'database' => env('DB_DATABASE'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

      

In .env

:

DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mytable
DB_USERNAME=root
DB_PASSWORD=1234
UNIX_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

      

+6


source


If none of the above solutions worked for you .....

Try to actually start your webserver as that was the fix for me :)

0


source


Make sure MAMP is set to Apache: 80, Nginx: 80, MySQL: 3306

Here's what worked for me with Laravel 5.7:

go to config / database.php and find line 54 below:

before: 'unix_socket' => env ('DB_SOCKET', ''),

After: 'unix_socket' => env ('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),

Save the file.

Then in terminal run: php artisan config: php artisan migrate cache

0


source







All Articles