How to destroy and recreate vagrant/homestead machine? - laravel

I'm running Laravel on Vagrant Box (homestead)
When I'm doing vagrant up, I'm getting a message:
: A newer version of the box 'laravel/homestead' is available and already
: installed, but your Vagrant machine is running against
: version '6.3.0'. To update to version '7.1.0',
: destroy and recreate your machine.
What commands should I run and what are potential problems I should be prepared for?

You can create a second installation for Homestead before you destroy the working one.
1) follow official documentation on installing Installing The Homestead Vagrant Box, then, when Installing Homestead instead of this command
git clone https://github.com/laravel/homestead.git ~/Homestead
run this one
git clone https://github.com/laravel/homestead.git ~/MyHomestead
then you'll need to cd ~/MyHomestead and git checkout v8.4.0
now you need to go to ~\MyHomestead\scripts\homestead.rb file and replace homestead-7 to homestead-7-my it will give you a different name for virtual machine in your virtualbox.
Now you can follow the official documentation
1.1) and you can always destroy your old vagrant box from your vagrant folder usually ~/homestead by running
vagrant destroy
2) create a new vagrant box by running
vagrant up --provision
3) get in to vagrant
vagrant ssh
4) go to your project (I assume you have a set of database migrations and seeders )
cd ~/code/myproject
4.1) you'll find redis and mysql is working there already.
5) create database
php artisan migrate
6) make SUPERVISOR works if you need it
7) make cron work if you need it
Done

As ceejayoz mentioned, you do not have to do this, you can just continue running the same version. Homestead is meant to be able to be torn down / built back up quickly, with all configuration living within the Homestead.yaml and Vagrantfile files. It's supposed to be able to do the heavy lifting for you with those config files.
As you mentioned, you have your database in Homestead. If you have some data there that is not local test data, ensure you get that exported before destroying. Some people manually modify their Homestead VM via SSH which is not recommended (as you should be using the Homestead.yaml file for changes), but if you have, keep a list of the changes you made and where you made them.
Here is a rundown of things you may want to keep before destroying:
Your Homestead.yaml file, just in case
Your Vagrantfile file(s) (if you've made custom changes)
Database data
Files used / generated by your application (logs, for instance.)
aliases file, if you've made custom changes to it
Elasticsearch data (if you use it)
Neo4j data (if you use it)
As for commands to run, the documentation says it better than I ever could: https://laravel.com/docs/5.7/homestead#updating-homestead

Related

Laravel Homestead - random "failed to extract" errors

Windows 10 / VirtualBox / Vagrant / Homestead
I've begun experiencing random errors like the following every time I run laravel new PROJECT:
85/95 [=========================>--] 89% Failed to extract laravel/framework: (2) unzip -qq '/home/vagrant/code/PROJECT/vendor/composer/tmp-f4716ecd4eeb00c7e1d90a043cc4a5b5' -d '/home/vagrant/code/PROJECT/vendor/composer/123a874a'
/home/vagrant/code/PROJECT/vendor/composer/123a874a/laravel-framework-6350d19/src/Illuminate/Database/Eloquent/Collection.php bad CRC 5a1bfd51 (should be 58446226)
The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
Unzip with unzip command failed, falling back to ZipArchive class
The errors occur on different packages each time. Sometimes the process completes and displays Application ready!, many times it fails.
So far I've tried:
composer clearcache
reinstalling vagrant
reinstalling vagrant laravel/homestead box
reinstalling homestead
deactivating the Windows Linux subsystem. I had enabled it for another purpose around the time the errors began, and wondered if it did something with case sensitivity.
All with no effect. Any ideas?
Solved
Finally made it work only by reinstalling VirtualBox, Vagrant, the Vagrant homestead box, and Homestead. Before reinstalling VirtualBox and Vagrant, I removed my homestead directory and all related application data files (in my case located in C:\Users\USERNAME).
It appears networking issues within VirtualBox were corrupting files pulled by "git clone" commands in the "laravel new" process.

Vagrant dev build throwing errors

So I am having some issues with vagrant. I had initially tried to report this as an issue on the vagrant github issue boards, but they kept closing the issues without responding to them. I guess they decided I wasn't worth their time, or they were just behaving unprofessionally. Anyway, Here is the problem: I use vagrant with virtualbox, and a new version of virtualbox was recently released that is, unfortunately, not compatible with the latest vagrant installation.
However, the people at hashicorp have already updated the source code so that it is compatible with the new version of virtualbox, but you have to build the vagrant executable from the source repo (instructions here). So I followed the instructions and vagrant is working just like it used to.....when the only command I need to run is vagrant up. I should also mention ahead of time that, in order to run the vagrant dev build, the current working directory needs to be the root of the source code repo and the dev build can only be run using the following command with ruby:
bundle exec vagrant
With that being said, I needed to update one of my custom boxes, so I built a vm in the updated version of virtualbox and ran the below command
bundle exec vagrant package --base go --vagrantfile ../../vagrant/vagrantfile
After an extended period of time, vagrant spat back out the following error
The executable 'bsdtar' Vagrant is trying to run was not found in the %PATH% variable. This is an `error. Please verify this software is installed and on the path.`
I should also note that I use a windows machine and that this error never occurred when using the installed version of vagrant. At this point, I had posted the issue on github to get some input from the devs, but they (very unprofessionally) decided to ignore my requests for help and close the issues without providing any response. I used the GNUwin32 project to make numerous unix commands available to my Windows environment and added the folder to my PATH environment variable. I then run the same command again to create my new box and it works!! So then I upload it to the vagrant cloud and attempt to update the vagrant box that is stored on my system by running the following command:
bundle exec vagrant box update
Then, after waiting for a while, vagrant then spat this error out at me:
The box failed to unpackage properly. Please verify that the box
file you're trying to add is not corrupted and that enough disk space
is available and then try again.
The output from attempting to unpackage (if any):
C:\gnuwin32\bin/bsdtar.EXE: invalid option -- s
Usage:
List: bsdtar.EXE -tf <archive-filename>
Extract: bsdtar.EXE -xf <archive-filename>
Create: bsdtar.EXE -cf <archive-filename> [filenames...]
Help: bsdtar.EXE --help
Another error, and still involving this bsdtar tool. It does not appear that anyone else is reporting the issue I am running into because I think they are just waiting for hashicorp to release the new official installation, but, just to give you a look into their priorities, the version of virtualbox that was released which no longer worked with vagrant was released back on December 10. It has been over a month since and there is still no updated release.
So, I am hoping that someone out there might be able to find out why I keep running into these errors when trying to use vagrant's dev build and provide a solution. If not, then maybe if someone else is able to reproduce the issue and report it to hashicorp, maybe they will listen to someone else.
If you are on Ubuntu 20.04 then bsdtar was removed. Try to install libarchive-tools package.
$ sudo apt-get install libarchive-tools
I figured it out. My original hypothesis was correct: since vagrant is a tool that was built primarily to be run on linux machines, then vagrant runs in windows, the installation includes a mingw environment with all of the dependencies vagrant needs to function and which the installed vagrant executable imports into the console session when run. This why the dev build kept failing: because it was not importing this mingw environment. So, in order to fix the issue, I first cloned the vagrant source code repo from github and followed the instructions I linked to above to build the executable from the source repo. I then copied all of the files in the source repo into the following folder:
<hashicorp install folder root>\Vagrant\embedded\gems\2.2.6\gems\vagrant-<version num>
So, for me, the destination directory is C:\HashiCorp\Vagrant\embedded\gems\2.2.6\gems\vagrant-2.2.6
This directory is identical to the source code repo, and copying the source code repo to the above folder replaces the installation version of vagrant with the dev build. After I did this, running the vagrant commands which had failed previously normally (as in, without using ruby or bundle) worked. I hope this helps someone else out there who Hashicorp has decided is not worth their time.

Upgrade php to 5.6 in Vagrant provisioning

I upgraded php to 5.6 within the Vagrant box 'trusty64', and also installed SOAP client. When I next update Vagrant I'm thinking it might overwrite these changes. Would I also need to change the provisioning in the vagrantfile, and if so what should I add?
When I next update Vagrant I'm thinking it might overwrite these
changes.
No, You would not loose anything if you upgrade vagrant. Once the VMs are created, vagrant will operate those VMs and upgrading vagrant will not impact the existing VM.
Basically, it works like this:
- when you run vagrant up, vagrant clone the box (which is VM files) and add the VM to VirtualBox
- after the VM have been created, vagrant "operates" (i.e. start, stop ...) the VirtualBox VM for you
Would I also need to change the provisioning in the vagrantfile
Thats necessary to change the provisioning if you plan to create more VM of this kind, or if you will destroy and recreate this VM; in this case the provisioning will run and you would need to have it updated.
and if so what should I add?
save all the commands you have run to run the upgrade and create a shell script out of it, might be the most simple option. You can also look at more advanced tool (puppet, ansible, chef .... that would do this job)

Laravel Homestead vagrant up box issue

I am installing laravel homestead. As I am new on this so maybe i took some steps wrong while installing and setting up laravel homestead on windows.
I followed a tutorial and download laravel homestead box directly and then install it manually by giving it a local disk url. It installed perfectly fine till then. But now when i am trying to "vagrant up" command it says that box doesnt found.
So after that I read somewhere that it we have to add manyual metadata somewhere but I dont know where. And after some changes I am facing this error.
Once you have downloaded the box manually, you need to add it to vagrant config, so vagrant knows about the box for later user. run the following command :
$ vagrant box add --box-version <VERSION_DOWNLOADED> laravel/homestead <path to downloaded file>
After this, make sure to go to the folder where homestead has been cloned (do not do that from the .vagrant directory, just go somewhere else, and avoid path with space, windows generally does not like it; C:\homestead will be just fine for a test) and you can run vagrant up from there

Laravel Homestead: Adding an additional virtual machine using vagrant box

There has been a recent change lately when attempting to clone the laravel/homestead package from GitHub. I haven't had trouble in the past trying to add additional virtual machines to my system but now I'm running into a problem.
If you go into GitHub to look at the latest repository for Laravel Homestead you will see that the 'homestead.yaml' file is not in the root directory any longer and has now been replaced by the file 'homestead'.
In the past, I have used the steps below for creating additional virtual machines in my command prompt:
1) Create a new directory (Code2) from within the root directory where VirtualBox and VagrantBox are installed
2) Go into 'cmd' and change to 'Code2' directory
3) Type in 'vagrant box add laravel/homestead --force'
4) Type in 'git clone https://github.com/laravel/homestead.git Homestead_temp'
5) Go into the newly created 'Homestead_temp' directory, copy and paste the files from inside that directory into your 'Code2' root directory.
6) Edit 'src/stubs/homestead.yaml' so that it contains the correct paths for your 'Code2' directory.
7) Go back into 'cmd' and type in 'vagrant up'. When I try to do this, I keep getting a 'read: No such file or directory C:/Users/Jeff/.homestead/Homestead.yaml'
I haven't had trouble in the past adding additional virtual machines but now I am prevented from doing so. Any help is greatly appreciated.
I'm not really sure if this answers my question or not, I'll have to do some research on it but for anybody that is curious about the recent Laravel Homestead changes, check out this article for Laravel 2.0
Hope this information helps!

Resources