To run Homestead, the following software must be installed on your host machine.
Install vagrant by downloading the latest version (currently: v2.0.1 as of January 29th 2018)
Install virtual box by downloading the latest version (currently: v5.2.6 as of January 29th 2018)
If you are unable to install due to an error in the installer, follow these steps:
- Unmount the
VirtualBox.dmg
- Open
System Preferences > Security & Privacy
- On the first tab, look at the bottom of the panel
- Allow the exception
- Remount the
VitrualBox.dmg
- Run the installer
If you want to use PHPMyAdmin, simply download the tar
file from their website and extract it to a directory similar to listed below in the example Homestead.yaml
file
For simplicity sake and support for Laravel based projects, we will be using the laravel/homestead vagrant box. To install Homestead first clone the repo to your home directory
git clone https://github.com/laravel/homestead.git ~/Homestead
cd ~/Homestead
git checkout v7.0.1
bash init.sh
vagrant up
If you get the following error, then please visit the link below.
==> homestead-7: Waiting for machine to boot. This may take a few minutes...
homestead-7: SSH address: 127.0.0.1:2222
homestead-7: SSH username: vagrant
homestead-7: SSH auth method: private key
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
https://stackoverflow.com/questions/41064388/laravel-homestead-vagrant-up-times-out
To be able to run commands on your homestead box from any directory in terminal, you can add the following to your ~/.bash_profile
or ~/.bashrc
file.
function homestead() {
( cd ~/Homestead && vagrant $* )
}
We need to update our Homestead.yaml file. This is used to provision the environment based on the box we selected.
vi ~/Homestead/Homestead.yaml
Configure the sections of your Homestead.yaml file according to where you keep your code repositories. For myself, that looks like this:
folders:
- map: ~/Code # local directory where you keep projects
to: /home/vagrant/code # virtual machine
sites:
- map: phpmyadmin.test
to: /home/vagrant/code/phpmyadmin
php: "7.2"
- map: reliance.test
to: /home/vagrant/code/reliance
php: "7.0"
databases:
- reliance
In order to view these newly created projects as they are hosted by Vagrant, you will need to update your /etc/hosts
file on mac
sudo vi /etc/hosts
And add the following lines to the bottom of this file:
192.168.10.10 phpmyadmin.test
192.168.10.10 reliance.test # these should reflect your Homestead.yaml file
You will periodically need to make changes to your various Vagrantfiles (or in this case, your Homestead.yaml files). The VagrantFile will pick up these changes for this yaml file when you provision your environment.
The following 4 commands should cover you in most cases.
vagrant global-status
shows you a list of existing machines and their state. This ID will be used in subsequent commands.vagrant global-status --prune
will clear the cache of the list of active machines (useful if you delete your Homestead directory to reinstall)vagrant up
should be run from the folder where the VagrantFile you wish to use is saved. (i.e.~/Homestead
is where our VagrantFile is. When you run this command in that folder, it will use the Configuration file specified in the VagrantFile.vagrant up --provision
will force VirtualBox to apply any changes that were made to theHomestead.yaml
orVagrantFile
vagrant destroy <machine-id>
will remove the machine in case of any peculiar behaviour and allow you to rebuild your box
In the event that you need to change your Homestead.yaml file, you can provision these changes to your environment by following the steps below. First, let's destroy our machine
vagrant global-status # take note of the ID
vagrant destroy <ID>
Then, we can bring our machine back online taking in the changes to the Homestead.yaml
cd ~/Homestead
vagrant up --provision
You should now be able to visit http://phpmyadmin.test
(or http://homestead.test
if you didn't install phpmyadmin) in your browser and see the application.