Setup of Lumen using Laravel Homestead vagrant box

Lumen is the stunningly fast micro-framework by Laravel. Lumen attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as routing, database abstraction, queueing, and caching.

lumen

I believe if you can setup the software easily then development becomes very easy and less frustrating. If you are not aware of some terms like virtualbox, vagrant, homestead I will try to explain them first before we heading towards the setup.

Prior knowledge


Mandatory to have some basic knowledge in linux commands which will help you to setup lumen in your local machine.

What you will learn from this article


  • What is Virtual Box
  • What is Vagrant
  • What is Vagrant Box
  • Laravel Homestead
  • Lumen setup

What is Virtual box?

Virtual box provides an emulated environment which can load multiple guest Operating Systems (guest OS) under a single host operating-system (host OS). Each guest can be started, paused and stopped independently within its own virtual machine (VM). The host OS and guest OSs and applications can communicate with each other through a number of mechanisms including a common clipboard and a virtualized network facility. Guest VMs can also directly communicate with each other if configured to do so.

Ex – If you have windows machine and you want to setup Lumen in Linux environment. So here Windows OS is host and Linux OS is guest. Using above virtual box you can add guest OS in your host OS. Download the virtual box from here as per your OS. Read more about Virtual Box.

What is Vagrant?

As mentioned in virtual box paragraph, you can add multiple guest OSs. So Vagrant is a software through which you can manage virtual box environment. Once you configured vagrant and virtual box then it is easy to setup your environment and share the exact environment across your team either through vagrant box or vagrant file. Developer having same vagrant file just need to vagrant up without setting up the environment manually. Download the vagrant software here as per your OS. Read more about Vagrant.

What is Vagrant Box?

Vagrant box is a package of all software installed in your guest OS including OS. There are public and private vagrant boxes available, which you can just download and add to your virtual box. Public box means people have already packaged all the softwares, made a box and shared it publicly. Similarly if you just package all your softwares and make a box and share with your colleagues will be called private box. Discover more public boxes here. Read more about Vagrant box

Laravel Homestead

Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes!

You will get all simple steps to install Laravel Homestead from this link https://laravel.com/docs/5.6/homestead and follow all the instructions as mentioned.

I just want to add few more simple steps which I found developers might get confused during Homestead box setup. Open homestead link https://laravel.com/docs/5.6/homestead in another tab and read my below points to get better understanding.

Point 1:

Screen Shot 2018-07-21 at 3.58.37 PM

Here if the above command throws error then run this command:

vagrant box add laravel/homestead https://vagrantcloud.com/laravel/boxes/homestead-7/versions/0.2.1/providers/virtualbox.box

Mainly you need to find the laravel homestead box and download it if vagrant box add laravel/homestead does not work.

Point 2:

Screen Shot 2018-07-21 at 4.09.56 PM
Screen Shot From Laravel Site

After running above command inside a directory type ls to list out the files got created. Here you will find Vagrantfile also got created. Don’t change the vagrant file content at all or replace it with you any existing Vagrantfiles.

2.png

Point 3:

Screen Shot 2018-07-21 at 4.50.53 PM.png
Screen Shot From Laravel Site

Here inside Homestead.yaml file map: ~/code means the folder which will be synced from your host machine. This directory name can be anything where all of your project resides. You can think of /var/www/html folder as well where we keep all of our project directories.

And to: /home/vagrant/code means the folder of your vagrant machine will have all the files available in mapped folder from your host machine. So no need to change this path. Let me share scree shot of my synced folders between vagrant and my host machine.

Screen Shot 2018-07-21 at 5.03.57 PM
Folder of Host Machine
4.png
Folder created during git clone as mentioned in Laravel site
3.png
Vagrant Folders

You can find out the folders got synced between host and vagrant box.

Point 4:

When you will do vagrant up inside the directory where you run init.sh file make sure you see the message about your folders got synced like below.

6.jpg5.jpg

Point 5:

Screen Shot 2018-07-21 at 5.29.07 PM.png

The ip 192.168.10.10 it gets generated by Homestead and you will find the ip on top of your Homestead.yaml file. So don’t change this IP as well. Use this ip in your /etc/hosts to link to the domain you will use to browse your project.

Lumen setup:

Once your folders get synced then install lumen inside your map: directory in your host machine. In my case it is ~/code. Follow https://lumen.laravel.com/docs/5.6 to install lumen in your directory which will be synced automatically to vagrant box. After I installed lumen when I typed lumen new blog it created project blog having lumen framework structure and all necessary files needed for Lumen.

Screen Shot 2018-07-21 at 5.35.57 PM.png

Ultimately I need to point the domain to this public folder, so this point will be like this:

Screen Shot 2018-07-21 at 5.38.36 PM.png

Here in my case it will be to: /home/vagrant/code/blog/public because /home/vagrant/code = ~/code and then after I need to point blog/public.

Once you cross verify all these things then browse your domain and it should work and you are done with setup 🙂

Please feel free to ask questions if you have any.

Thanks for your time to go through the article.

Thanks!

References:

https://laravel.com/docs/5.6/homestead

https://lumen.laravel.com/docs/5.6

https://www.virtualbox.org/wiki/Downloads

https://www.virtualbox.org/wiki/Downloads

https://www.vagrantup.com/docs/virtualbox/

https://www.vagrantup.com/intro/index.html

Leave a comment