Skip to content

Instantly share code, notes, and snippets.

@cregx
Last active May 22, 2024 07:15
Show Gist options
  • Save cregx/6015ac4592ea75795815a22c50302166 to your computer and use it in GitHub Desktop.
Save cregx/6015ac4592ea75795815a22c50302166 to your computer and use it in GitHub Desktop.
How to update Vagrant box laravel/homestead to a new version

How to update Vagrant box laravel/homestead to a new version

This manual was last checked for validity on January 28, 2023.

Introduction

This how-to describes the process of updating Laravel/Homestead boxes within the Vagrant environment. Those who use Vagrant for the development of (web) projects know the issue: updates become available several times a year, and then you have to recall what this simple update process entailed.

The instructions described here refer to a macOS environment.

MySQL is used as a database system.

VirtualBox ist used as a virtualization provider.


You see if an update for the Laravel/Homestead box is available during Homestead startup.

vagrant up

vagrant-up

Step 1: Back up your MySQL databases

Make sure that all your Homestead databases have been backed up.

Login to the Vagrant environment via ssh ...

vagrant ssh

... and create a directory for the database backup (if not exists). It is recommended to backup the databases in this directory in the future and also to integrate this directory into a central data backup system on the host.

Important

Make sure that the backup directory is located in the mapped space of the host. Otherwise the directory will be deleted when the current environment is destroyed afterward.

To get more information about this see also in your Homestead.yaml

mkdir backup_databases_homestead

Execute the following command to backup all databases and then shut down vagrant. For MySQL the syntax looks like this:

The default password for the MySQL root user within the laravel/homestead is: secret

Tip! I would use both variants of the backup strategy mentioned below. In this case, more can't hurt.

mysqldump -u homestead -p --all-databases > ./backup_databases_homestead/backup_from_2020_05_02.sql

Important

If you only want to backup certain databases, but they contain triggers or stored procedures, use this command:

mysqldump -u homestead -p --result-file=backup_incl_sp_and_trigger_from_2020_05_23.sql --routines --databases myDatabase1 myDatabase2.sql
logout
vagrant halt

Step 2: Download the latest available update

This process will take some time. So get yourself a coffee and relax.

vagrant box update

vagrant-box-update

Once the download is complete, you can view all available box versions.

vagrant box list

vagrant-box-list

Step 3: Update the laravel/homestead to the new version

First, the previously used version of the laravel/homestead box must be destroyed, and then the Vagrant environment must be booted. An update process to the new box version is automatically performed.

Warning! Have you remembered to back up your databases? The vagrant destroy command also destroys any existing databases!

vagrant destroy

vagrant-destroy

vagrant up

vagrant-up-after-destroy

Step 4: Restoring MySQL databases and reload of permissions

After the automatic update has finished, the MySQL database can be restored and all cached permissions reloaded (flush privileges). To do this, the backup of the MySQL databases created before (step 1) must be restored from the directory backup_databases_homestead.

vagrant ssh
...
mysql -u homestead -p < ./backup_databases_homestead/backup_from_2020_05_02.sql
...

Do not forget to restore the alternative database backup, if available (backup of databases containing stored procedures or triggers).

Tip! I once had the following problem: "DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled." The problem solution was => Execute the following in the MySQL console:

SET GLOBAL log_bin_trust_function_creators = 1;
...
mysql -u homestead -p
...
mysql> flush privileges;
mysql> quit
logout

mysql-flush-privileges

Step 5: Cleaning up unneeded box versions

The last step is to delete box versions that are no longer needed. As a rule, this should at least be the last valid box before the update.

vagrant box list
vagrant box remove laravel/homestead --box-version=9.4.0

vagrant-box-remove


Disclaimer

This manual or parts of it are provided "as is" without warranty of any kind.

MIT License

Copyright (c) 2020 cregx

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment