This manual was last checked for validity on January 28, 2023.
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
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
This process will take some time. So get yourself a coffee and relax.
vagrant box update
Once the download is complete, you can view all available box versions.
vagrant box list
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 up
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
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
This manual or parts of it are provided "as is" without warranty of any kind.
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.
Update the clone of the laravel/homestead repository if the
vagrant box update
command in the 2nd step fails as below.Use the commands below to update the clone of the laravel/homestead repository.
Execute the
vagrant plugin update
command if you run into the error below.Remove the existing version of the box using the command below if the
vagrant box update
command fails to fetch the newer version.Remove the existing version of the box using the command below
Then run the
vagrant up
command. It will download the newer version of the laravel/homestead box and install it before starting the box.