Homestead

Deprecated — this content is not maintained and possibly out of date.

2018-12: I switched from Homestead to Valet Plus to avoid running VMs.

2021-05: I switched from Valet Plus to Valet because my personal sites don’t have databases.

Homestead is a Vagrant box that simplifies creating a PHP/MySQL/nginx environment.

Install

I put Homestead here (the default place):

cd ~/Homestead

Configure

Add the folder and site mappings:

# Edit with nano
nano ~/Homestead/Homestead.yaml

# Or edit with Atom
atom ~/Homestead/Homestead.yaml

Update hosts file:

sudo nano /etc/hosts

Example entries:

192.168.10.10 laravelscratch.test
192.168.10.10 shop.gravitydept.test

Reload the Homestead (Vagrant) box:

homestead reload --provision

Reference

Using the VM

# Change directory
cd ~/Homestead

# Start the VM
vagrant up

# Provision the VM (won't lose your data)
vagrant provision

# Provision something stubborn
vagrant reload --provision

# SSH into the VM
vagrant ssh

# Stop the VM
vagrant suspend

Make an alias

It’s annoying having to leave your project directory to start the VM. Add a function to your bash profile:

function homestead() {
    ( cd ~/Homestead && vagrant $* )
}

Now you can be inside any folder and run these:

homestead up
homestead provision
homestead reload --provision
homestead ssh
homestead suspend

Reference

Update

cd ~/Homestead

# Update the Git repo
git pull

# Update the vagrant box
vagrant box update

When updating Virtual Box, you might need to restart your Mac before Homestead updates will work. Provisioning or recreating the box sometimes isn’t enough.

Platform tricks

For Laravel

Works great. Homestead was made by Laravel.

For Statamic

Works great with one modification for the Statamic admin.

Edit ~/Homestead/scripts/serve-laravel.sh and find this code:

location / {
    # GravDept: add this line for Statamic
    rewrite ^/admin.php.*$ /admin.php;
    # GravDept: end

    try_files \$uri \$uri/ /index.php?\$query_string;
}

Remember to run homestead provision afterward.

Reference