What you need for this book
To ensure a consistent development environment and prevent unnecessary alterations to your host operation system, it is highly recommended that you run all commands within a Linux virtual machine. This will ensure that your output both in your web browser and from your command line matches the output that is presented in this book. As setting up this environment on your own can be a daunting task, prebuilt virtual machines that use VirtualBox and Vagrant are provided to make this setup process easy.
To get started with this book, you should be running the latest version of either Microsoft Windows 7, 8, 8.1 or 10, Apple OS X 10.9 or higher, or a Linux operating system that can run virtual machines, such as Ubuntu 14.04 LTS. Additionally, you will need to install the latest version of VirtualBox (available at https://www.virtualbox.org/wiki/Downloads) and Vagrant (available at https://www.vagrantup.com/downloads.html).
Note
After installing these software dependencies, you may need to restart your computer for the changes to take effect.
After installing VirtualBox and Vagrant, you can then create a new dedicated development environment by opening a new command line or terminal window, creating a new directory for the chapter, and then running the following command to create your virtual machine development environment. These commands will download a prebuilt virtual machine containing all the software required to get you started and start your new development environment:
vagrant init charlesportwoodii/php56_trusty64 vagrant up --provider virtualbox vagrant ssh
Note
More information on this specific Vagrant box can be found at https://atlas.hashicorp.com/charlesportwoodii/boxes/php56_trusty64.
Note that if you are on Windows, you may need a tool such as PuTTy to connect to your virtual machine over SSH. More information on how to connect to your new virtual machine over SSH on Windows can be found at http://docs-v1.vagrantup.com/v1/docs/getting-started/ssh.html.
Once your new Vagrant box has started, you can access the files of this virtual machine over SSH and access your webroot
directory by opening a new browser window and navigating to http://localhost:8080
. By default, when you open this web page, you will see the output of phpino()
.
Tip
Depending upon your operating system security settings, your computer may prompt or block you from accessing port 8080 on your computer. Ensure that you configure your firewall settings if you are facing issues and ensure that port 8080 is open on your computer and that VirtualBox can forward connections from your host operating system to your guest operating system.
As Yii2 is fully compatible with PHP7, it is strongly suggested that you develop and test your web applications against PHP7 as well. The following commands will allow you to provision a PHP7 Vagrant box:
vagrant init charlesportwoodii/php7_trusty64 vagrant up --provider virtualbox vagrant ssh
Tip
As these virtual machines automatically configure port forwarding, it is recommended that you only run a single virtual machine at a time. Refer to the Vagrant documentation for a complete list of commands and configuration options at https://docs.vagrantup.com/v2.