Vijay Anandh
Vijay Anandh

Reputation: 46

Laravel 5.6 connect refused using MAMP server

I am using MAMP PRO local server with configured PHP 7.1 and mysql 5.6.38. Install Laravel 5.6 using composer and edit .env file as the following,

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=sample
DB_USERNAME=root
DB_PASSWORD=root

and run command PHP artisan make:auth. When I tried to log in, it returns SQLSTATE[HY000] [2002] Connection refused. I have changed DB_HOST=127.0.0.1. Still, it returns the same. Thanks in Advance

Upvotes: 2

Views: 5507

Answers (1)

user9896706
user9896706

Reputation:

Try adding the MySQL port to your database.php:

'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306')

Check one of the following things otherwise:

  1. Are you sure you haven't blocked your port completely, for remote and local usage?
  2. Have you double checked your MySQL port?
  3. If you're using MAMP Pro, be sure to add the unix_socket key with a value of the path that the mysql.sock file resides in MAMP.

( Point 3 can be done with adding the following code to your database.php)

'mysql' => array (
 'unix_socket' => env('UNIX_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock')
)

Upvotes: 8

Related Questions