Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run migrate on homestead when running migrate locally with Laravel?

I have to run migrations on the homestead box by SShing in:

homestead ssh
cd ~/Code/my-project
php artisan migrate

I would prefer to just run migrate on the local folder and automatically have the migrations run on the guest (virtual) machine.

like image 473
tread Avatar asked Oct 25 '15 18:10

tread


People also ask

How do I run a specific migration in Laravel?

To run the specific migration in Laravel, you need to use --path option with the php artisan migrate command. Let's take a simple example, we have '2019_12_04_131405_create_payments_table. php' migration in the database/migrations directory and we would like to run this migration.

How do I change php version to Homestead?

As a slightly simpler alternative to update-alternatives --config php you can enter the PHP version you want on the command line with a syntax of php71 where 7 is the major version and 1 the minor version. For example to switch to PHP 7.1 from another version simply type php71 .


2 Answers

By default, Laravel uses the localhost as the database host, just go to your homestead.yaml file and check the first line for the IP address (possibly is => ip: "192.168.10.10"). Use this IP as the host in your .env file:

In the .env file use: DB_HOST=192.168.10.10

Instead of DB_HOST=localhost

It must works.

PS: Homestead redirect the ports also, so possibly you need to change the port of the database to: 33060

In the .env file, use: DB_PORT=33060, instead of DB_PORT=3306

But, check first with the firt configuration.

Best wishes.

like image 83
JuanDMeGon Avatar answered Dec 14 '22 14:12

JuanDMeGon


The command you're looking for is: homestead ssh -c "cd ~/Code/my-project; php artisan migrate; exit".

Try to run it from your local console for testing it.

If it works, all you need is to create an alias for "migrate" that runs the above, and that's it.

like image 37
Meir Cohen Avatar answered Dec 14 '22 13:12

Meir Cohen