The Homestead Tool

Console Defined

Whenever you are prompted to do something from the console, context
is important.

The homestead console means connecting to the Homestead VM via SSH.
For Windows, this means using PuTTY (explained in the chapter on
setting up a Windows machine). With other operating systems you can
execute the homestead ssh command from within the terminal. Whenever
you see the $ prompt in this book you are in the homestead console.

The OS console means either the Windows command prompt or the terminal
application you use. (The % prompt in the book is used for your OS
specific console.)

From the console of your host operating system, you can easily see what the valid homestead commands are by typing the homestead command without any arguments.

The shared folders. These are the directories in your Host Operating System and where they will appear within the VM. For Windows the ~/Code equates to something like C:\Users\YOU\Code. In OS X, this is /Users/YOU/Code. Under Linux it’s usually something like /home/YOU/Code. Whenever you edit a file in this directory tree on your host machine, it’s instantly available to the Homestead Virtual Machine.

sites

A list of sites (paths each domain points to) that will be set up on the Homestead Virtual Machine each time you provision.

databases

A list of database Homestead should automatically create.

variables

Variables to make available to the homestead environment.

A configuration note

The only change I usually make to the configuration is to change the list
of databases to have one database named xhomestead instead of homestead.
This way if I forget create an app’s database when creating a new Laravel
application, an error occurs. (Otherwise, since the default
database for a new application is homestead, no error will occur and
I’ll be using the homestead db without realizing it.)

For now, don’t change any homestead configuration values except the databases setting (and then, only if you want to.)

The Homestead Virtual Machine Details

What

Value

Hostname

homestead

IP Address

192.168.10.10

Username

vagrant

SU Password

vagrant

Database Host

127.0.0.1

Database Port

33060

Database Username

homestead

Database Password

secret

Adding Software to the Homestead VM

When you need to install new software inside the Homestead Virtual Machine, use the Ubuntu utility apt-get.

It’s an easy two step process.

Upgrade Ubuntu

Install with apt-get

For example, here’s how to install unzip, a handy utility for dealing with zip archives.

This command sets up a new configuration file in /etc/nginx/sites-available for the domain we’ll be using (test.app) and a symbolic link to this file within the /etc/nginx/sites-enabled directory.

Even when you reboot the machine, this configuration file will be there.

Why not edit Homestead.yaml

Yes. Another alternative is to set up the parameters for the test.app
virtual host using the homestead edit command and adding a new entry to
the sites: section. But this is easier, and there’s no need to
continuously reprovision the Homestead VM.

But, if you’re setting up an app you always want configured, it’s not
a bad idea to edit Homestead.yaml and set up the configuration there.

Step 3 - Add the Host to Your Hosts File

Since test.app does not exist in any DNS, an entry must be added to the Host OS’s hosts file. Edit /etc/hosts in Linux or OS X. In Windows the file is C:\Windows\System32\drivers\etc\hosts. In this hosts file point test.app to the IP specified in Homestead.yaml.

Add the following line to this file.

Host entry for test.app

192.168.10.10 test.app

Windows requires admin privileges to edit hosts

In Windows you must launch your editor (such as Notepad, Wordpad,
or Sublime Text) as an administrator. In Linux or OS X you can use
the sudo command.

Editing hosts with Linux or OS X

sudo nano /etc/hosts
// or
sudo vi /etc/hosts

Step 4 - NPM Local Installs

In order to later use gulp it’s important to make sure all the required npm modules are locally installed.

Creating a Database in the Homestead VM

Once the database is created, edit the .env file in your project’s root directory and change the DB_NAME appropriately.

Change DB_NAME in .env

// Change the following line
DB_DATABASE=homestead
// To the correct value
DB_DATABASE=test

Easy. Now you’ll be able to migrate and create tables. This is covered in a later chapter.

Step 6 - Testing in the Browser

Point your browser to http://test.app and you should see the page below.

Figure 5.1 - Default Laravel 5.1 Page

If you see anything else then something didn’t work.

Other Homestead Tips

Edit Source Code in your Host Operating System

Although this has been mentioned in an earlier chapter, it bears repeating. Always edit your source code in your Host OS. Through the magic of shared folders, changes you make within the ~/Code directory are immediately seen within the Homestead Virtual Machine.

Use the .homestead/aliases file

Each time you re-provision Homestead with homestead up --provision or homestead provision, the .homestead/aliases file updates the aliases in the Homestead Virtual Machine.

This is a handy place to add aliases, or functions, or even other environment variables.

Keep the Homestead VM up-to-date

As mentioned earlier, two commands will keep the Ubuntu operating system within the Homestead Virtual Machine up to date.

Keeping Ubuntu Updated

$ sudo apt-get update
$ sudo apt-get upgrade

Recap

This chapter provided details on the homestead and laravel commands. And the Six Steps to a New Laravel 5.1 Project were outlined.