basagabi
basagabi

Reputation: 5064

Laravel vagrant homestead connect to xampp's mysql

I previously work on xampp to develop my laravel projects and it is just then that I switch my dev environment to use Vagrant + Homestead. I am able to successfully ran a fresh laravel installation thru homestead and is able to view the welcome page via browser using http://homestead.app

Now my next step is to connect it to the database. I know that Homestead already provides a homestead database but I do not want to use that but instead to connect to my current xampp mysql database.

How would I be able to connect my laravel app to my xampp's mysql database which is in the host computer?

On my config/database.php, I have set the following configurations.

'mysql' => [
    'driver'    => 'mysql',
    'host'      => '127.0.0.1',
    'port'      => 3306,
    'database'  => 'mydatabase',
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
    'strict'    => false,
],

I know that 127.0.0.1 refers to the homestead box itself but how to change the ip address of xampp to something else? Will changing the ip address resolve the issue or am I missing out something else?

Thanks in advance!

Upvotes: 0

Views: 1028

Answers (2)

Frederic Henri
Frederic Henri

Reputation: 53783

You can use the default gateway so changing the IP to 10.0.2.2 and you will connect to the db on your host

From your host, make sure not to run the DB server on the host IP, if you want to be fine for dev purpose you can run on 0.0.0.0 so it will listen on all network interfaces

Upvotes: 1

basagabi
basagabi

Reputation: 5064

I was able to fix this by:

  1. On the xampp's my.ini, add: skip-name-resolve
  2. On the laravel's database.php file, set host to 10.0.2.2.

Upvotes: 1

Related Questions