Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Abid's avatar
Level 11

Connect to Host Machine MySQL from inside Vagrant Box?

I'm looking for ways to connect my php projects (inside vagrant) to use host machine's MySQL connection. How can I do it?

Using Homestead if needed.

0 likes
6 replies
ChiefJS's avatar

@Abid Create a new connection on your MySQL browser with homestead as your user and and a password of your choice but let the password reflect what's on your .env file

Fuxy22's avatar

Create a homestead user with a password of your choice on the host machine go into your .env file and edit the user and password to be indentical to the one you just created and also don't forget to replace localhost with the host's IP address. For a default homestead install that would be 192.168.10.1 I believe.

That should do it.

1 like
unitedworx's avatar
Level 8

@Abid you need to use ip 10.0.2.2 in order to connect to your host machine. This is a standard IP that get configured on homestead. if you use your machines local IP then you will need to change it each time it changes, when e.g you connect to another network!

here is my .env db detail which connects on a mysql db on my host from inside homestead vm.

DB_HOST=10.0.2.2
DB_DATABASE=laravel52
DB_USERNAME=root
DB_PASSWORD=root
13 likes
chimit's avatar

A strange thing: the first time I got this problem @unitedworx solution helped me. But next time the reply by @Fuxy22 fixed my problem.

I'm trying to connect to a process running in a Docker container from the Homestead.

Please or to participate in this conversation.