This chapter discusses what software and components are required to develop applications with Laravel 5.1 and why they’re required. Instructions to install VirtualBox and Vagrant are provided.
- The Rise of the Virtual Machines
- About Laravel Homestead
- Installing Virtual Box
- Installing Vagrant
- Where Do I Execute Things?
The Rise of the Virtual Machines
Over the last few years, virtual machines have come into their own. Virtual Machines (or VMs) allow one computer system (the host operating system) to emulate another one. Sure, VMs have been around for a while, but now with increased processor speed and cheap memory VMs can be on every developer’s desktop.
Laravel embraces VM technology and packages it’s own “box” with the most common requirements for web applications. This pre-packaged development environment is called Laravel Homestead.
About Laravel Homestead
One of the driving philosophies behind Laravel is to make PHP development both fun and easy. To this end Laravel provides a pre-packaged development environment called Laravel Homestead. Vagrant is used to manage the virtual machine. Under the hood VirtualBox provides the interface to the host operating system.
A car is the perfect metaphor for how this all works together. Homestead is the driver’s seat of the car, Vagrant is the car’s frame, and VirtualBox is the engine. Once Vagrant and VirtualBox are installed, there’s no need to worry about them again. All interaction with the VM occurs through Homestead. (Just like when driving a car, there’s no need to worry about the frame or engine.)
Using Laravel Homestead allows you to use a virtual Ubuntu Linux machine, pre-installed with the software required for web development. This VM includes:
- Ubuntu 14.04
- PHP 5.6
- Node (With Bower, Grunt, and Gulp)
- Laravel Envoy
- Fabric + HipChat Extension
And best of all, using Homestead Vagrant allows the same development environment to be used on Windows, OS X, or Linux systems … without worrying about conflicting software on the host machine.
Installing Virtual Box
But if you don’t have a backend installed, you can install the VirtualBox platform package. It’s free and works on every major platform.
Figure 2.1 - Virtualbox Download Page
Go to www.virtualbox.org, download and install the package for your operating system.
Once you have VirtualBox (or another back-end provider) installed, you need to install Vagrant.
Figure 2.2 - Vagrant Home Page
Go to www.vagrantup.com, download and install the package for your operating system.
When the Vagrant installation is complete, you may need to reboot your machine. After the reboot, verify Vagrant is installed by opening the console (command prompt in Windows, terminal in OS X or Linux) and checking the version.
Checking the Vagrant Version
% vagrant --version Vagrant 1.6.5
Vagrant Windows Install Location
Unlike most software installed within Windows, Vagrant is not available
in the Windows Start menu. It installs into the
directory and adds
C:\HashiCorp\Vagrant\bin to your Windows
Where Do I Execute Things?
After going through the next few chapters installing and running Laravel Homestead a common question is “Where do I run …?” or “Where does … run?” This section provides a brief overview of the major components of Laravel development within Homestead and answers the questions.
The Web Server
The Web Server runs in the Homestead Virtual Machine.
Nginx is the web server used to serve the web pages. The Host OS can access the web pages using the standard HTTP port (80) at the address 192.168.10.10. The Host OS can also access web pages at 127.0.0.1 on port 8000.
Always edit your source code from the Host OS.
The edited files are immediately available in the Homestead Virtual Machine through shared folders.
MySQL runs within the Homestead Virtual Machine.
You can access MySQL from your Host OS with the following information.
|Setting Name||Setting Value|
Memcached runs within the Homestead Virtual Machine.
Memcached is an in-memory key/value cache.
Beanstalkd runs within the Homestead Virtual Machine.
Beanstalkd is a simple and fast work queue.
Git or Subversion
Run from your Host OS.
Although you can run these version control systems from either place, it is strongly recommended to only run them from your Host OS. Consistently running them in one location avoids potential conflicts.
For example, let’s say you install subversion in the Homestead Virtual Machine and it’s version 1.8. You check out source code within the Homestead Virtual Machine and then try to check it in from your Host OS. If subversion v1.7 is installed on your Host OS you won’t be able to do anything until upgrading subversion on your Host OS.
Run from either Homestead Virtual Machine or Host OS.
Bower is a simple to use package manager for the web. You can run this from either place if bower’s intalled on your Host OS.
ONLY run this from your Host OS.
Gulp is a simple build system Laravel Elixir uses to concatenate assets, minify assets, combine assets, copy assets, and automate unit tests.
For Windows, running Gulp on the Host OS is an absolute requirement. Under OS X and Linux running Gulp from your Host OS allows growl-like notifications to appear in your OS. (You can still run gulp successfully within the Homestead Virtual Machine in OS X or Linux, but will receive warning errors when notification attempts are made.)
Only run Composer from your Host OS.
If you’re Host OS is OS X or Linux you can run from either place, but if your Host OS is Windows then Composer creates necessary batch files required to operate correctly.
artisan from the Homestead Virtual Machine. The main reason for this is that any specific database, queue, and cache drivers are installed within Homestead and may not be available (or installed) on your Host OS. Also, the database setting of
localhost is from the Homestead VM perspective, not from your Host OS’s perspective.
The rule for running commands in the console
The rule is: Only run artisan in the Homestead VM. Everything else can or must be executed from your Host OS.
In this chapter we discussed the various software required to develop applications in Laravel 5.1 and installed VirtualBox and Vagrant.
If your machine is a Windows box, continue to the next chapter, Setting up a Windows Machine. Otherwise, skip to the chapter Setting up an OS X or Linux Machine.