Reputation: 88
I have been trying to connect to the database of my laravel/homstead box now for a while. I can successfully run php artisan migrate
once I ran vagrant up
& vagrant ssh
. I have tried plenty of solutions such as using localhost
instead of 127.0.0.1
and tried the host file ip 192.168.10.10
neither have worked.
host file:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
192.168.10.10 vueapp.local
192.168.10.10 laravelapp.local
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', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
],
.env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
I use TablePlus for Mac as mysql client
password used: secret
TablePlus connection settings screenshot
Solution
managed to connect via ssh. I have still no idea why the clients (I also tried sequel pro) timed out every time.
These are the settings I eventually used ssh vagrant default password is "vagrant"
Upvotes: 2
Views: 769
Reputation: 9045
I think you have your application installed in a vagrant container. But your database is inside your actual host mac machine in which virtulbox is installed.
When your application says host IP as 127.0.0.1
, thats your local loopback address of vagrant machine and not the mac machine on which vagrant is running.
So you can trying to connect the MySQL client installed in your mac machine to the application which resides inside a virtual container.
You can install MySQL inside the vagrant server so that your app can use it by pointing to host IP 127.0.0.1
.
Upvotes: 0