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.
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.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With