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' => '',
),
source to share
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.
source to share
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
source to share
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
source to share