Lessons: 9Length: 40 minutes

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

1.2 Setting Up Your Dev Environment

In this lesson, we’ll set up the Homestead virtual machine provided by the Laravel project, use it to create our Lumen project, and then make our first request against it.

Related Links

1.2 Setting Up Your Dev Environment

In this video, we'll walk through how to get your dev environment set up to work on the Lumen application. If you already have a local development stack with PHP composer and MySQL or some other type of relational database, you can probably skip this video. Or follow along if you'd like to learn a convenient way of setting that up, provided by the Laravel project. Typically getting your environment set up can be a lengthy process, where you have to install and configure PHP, Nginx, MySQL, composer, pretty much your entire stack. A popular way around this is to use a preconfigured virtual machine as your development box. The Laravel project provides a really good virtual machine that we can use called Homestead. Lumen is also part of the Laravel project, which makes Homestead a great fit for working on Lumen applications. You'll be able to setup Homestead regardless of whether you're running Windows, Mac OS ten, or Linux as your host operating system. Before we get started setting up Homestead, you'll need to have two pieces of software installed, VirtualBox and Vagrant. VirtualBox is a popular, free virtualization software that Homestead will run inside of. Vagrant is the industry standard tool for managing virtualized portable dev environments that come preconfigured for your needs. Go ahead and download both of those from their official websites before we continue. Once you have your virtualization software installed, you'll need for an SSH key pair to be available on your system. This is so you can get into the VM through SSH. If you've been developing with the machine you're using for a while, chances are you already have one. If not, it's easy to generate one. Let's go with a default key pair name id underscore rsa. Finally you'll need a folder where all your code repositories live. You probably have one already. Mine is at my homefolder slash repos. That's where our Lumen app is going to live once we create it. That's also where I"m going to the homestead project from git. Let's check out the homestead project now. When we install homestead, we'll assume that php is not installed on your host machine and and set it up as a git repo rather than install through composer. That there are no dependencies that exist outside the vm. Let's go ahead and install homestead now. Cd into the homestead directory and let's look around. You'll see a Vagrant file, which houses a configuration that our vm will get built from. That's already filled out, so we don't need to worry about it. Let's install homestead onto our system by running the init bash script. That script created a hidden folder for us called .homestead. Let CD into that directory and see what got put in there. You'll notice a homestead.yaml file. That file is how Homestead knows which websites it should be hosting, which databases it should have available, and which folders of code from your host system should be available from inside the VM. The IP field is the IP address that our VM will have once it starts up. We've got two gigs of RAM and one CPU core available to the VM. Those defaults work well for now, but feel free to adjust those to your liking. The authorized and keys fields correspond to the SSH key pair that we're using to connect to the VM. If you generated your key pair with the default name, ID underscore RSA, this should just work. The folder section is where we map folders on your host machine to folders inside the vm. I picked home slash repos as my code folder, and since we log into the vm as the Vagrant user, the destination folder is going to be home, vagrant repos. The site section is where we tell enginex, running inside the vm from what URLs we can see our projects inside the browser. Let's make a new site, call it bookmanager.app and map it to slash home, slash vagrant,slash bookmanager, slash public. The public folder is going to be the document root of our Lumen project once we've created it. Let's add a database for our new Lumen project, call it bookmanager. Looks like we're all done inside this file. Next, we need to add an entry to our host file which maps the URL mylumenproject.app to the IP address of your VM. That way, when we try to view the project in the browser, it'll go to the right place. Now we need to add homestead as a base box that's available to Vagrant on this machine. We do that with the Vagrant box add command, followed by the name of the box. It'll take a little while for it to download. Now that the homestead base box is available, let's fire up the vm and see if it works. From inside the home repos homestead directory, run Vagrant up. Since we're running the VM for the first time, it'll take a while for vagrant to configure and install everything. Once the VM is done booting, go ahead and connect to it by typing Vagrant SSH. You'll end up in home slash vagrant. Run LS to take a look around. You'll see your code folder there. We'll be using the Lumen command to create our project, but first we'll need to make that command available inside our VM by installing it with Composer. Let's go ahead and create our Lumen project inside the code folder we set up. We should be all done setting up now, let's load up our Lumen project in the browser now and see if it works. And here we have the default Lumen index page, which means we're ready to start building out our app. In the next lesson we'll add a little more configuration but this time at the application level. We'll also be setting up our database with a schema and some sample data.

Back to the top