Updating Laravel Homestead
(!) Notice: this post is probably outdated
Recently I needed to update my Homestead VM to a more recent version, because I needed to run PHP 7.2. While you can just update PHP on a current Homestead instance, I was using a very old Homestead version and wanted to update it.
Moreover, I wanted to make sure I could do that in case something went wrong sometime. Also, that meant I had to have everything backed up.
My first instinct was to check the official documentation. However, there are a few missing steps there, so I started googling and… StackOverflowing? around. I thought I put this into a post, so I can refer to it later:
Back everything up (!)
If you have your projects in shared folders between your machine and the VM, you don’t need to back those files up, since those live in your machine. Anyways, always good idea to have those backed up regularly.
What you do need to back up is all your databases. One option, if you have a few databases, is to log in to your MySQL instance and export each one. Another more convenient one is to dump everything (and restore later) using a simple dump. SSH into your VM and from your shared folder, type:
mysqldump -u homestead -psecret --all-databases > homestead-backup.sql
Also, back up your ~/Homestead/Homestead.yaml, since it holds all your websites’ configurations.
Upgrading Vagrant box
Go to ~/Homestead and run
vagrant box update
This will update your Vagrant box to the latest laravel/homestead version. You should see the newly upgraded box by running vagrant box list.
Destroy current Homestead
We should now destroy the current Homestead environment, by running from ~/Homestead:
vagrant destroy
Update Homestead
If you installed Homestead via git the previous time, you can update it running
git pull origin master
If not, you can remove/delete the current Homestead folder, go to ~/ and run:
git clone https://github.com/laravel/homestead.git Homestead
Then, just to be sure, check a specific version:
cd Homestead
git checkout v6.5.0
After that, initialize Homestead by running:
bash init.sh
Once you’ve done that, you can update your current Homestead.yaml settings from the backup. You did back up, right?
Lastly, you can restore all your MySQL databases by SSH’ing into the VM and running:
mysql -u homestead -psecret < homestead-backup-2017.sql
Free up space
After upgrading, you can free up space by removing unused Vagrant boxes. To see all the Vagrant boxes, run:
vagrant box list
To delete them, run:
vagrant box remove laravel/homestead --box-version=0.4.0