Skip to content

Instantly share code, notes, and snippets.

@cregx
Last active September 20, 2024 15:33
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.

@hsumudupriya
Copy link

hsumudupriya commented Sep 20, 2024

Update the clone of the laravel/homestead repository if the vagrant box update command in the 2nd step fails as below.

$ vagrant box update
==> homestead5-6: Checking for updates to 'laravel/homestead'
    homestead5-6: Latest installed version: 12.0.0
    homestead5-6: Version constraints: >= 12.0.0, < 13.0.0
    homestead5-6: Provider: virtualbox
There was an error while downloading the metadata for this box.
The error message is shown below:

schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.

Use the commands below to update the clone of the laravel/homestead repository.

git fetch origin
git pull

Execute the vagrant plugin update command if you run into the error below.

$ vagrant box update
Vagrant failed to initialize at a very early stage:

The plugins failed to initialize correctly. This may be due to manual
modifications made within the Vagrant home directory. Vagrant can
attempt to automatically correct this issue by running:

  vagrant plugin repair

If Vagrant was recently updated, this error may be due to incompatible
versions of dependencies. To fix this problem please remove and re-install
all plugins. Vagrant can attempt to do this automatically by running:

  vagrant plugin expunge --reinstall

Or you may want to try updating the installed plugins to their latest
versions:

  vagrant plugin update

Error message given during initialization: Unable to resolve dependency: user requested 'vagrant-vbguest (= 0.30.0)'

Remove the existing version of the box using the command below if the vagrant box update command fails to fetch the newer version.

$ vagrant box update
==> homestead: Checking for updates to 'laravel/homestead'
    homestead: Latest installed version: 12.0.0
    homestead: Version constraints: >= 14.0.2, < 15.0.0
    homestead: Provider: virtualbox
    homestead: Architecture: "amd64"
==> homestead: Box 'laravel/homestead' (v12.0.0) is running the latest version.

$ vagrant box list
laravel/homestead (virtualbox, 12.0.0)

Remove the existing version of the box using the command below

vagrant box remove laravel/homestead

Then run the vagrant up command. It will download the newer version of the laravel/homestead box and install it before starting the box.

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