In past days, I talked about a mischievous issue in supported PHP installation by macOS when I was trying to configure an app in Laravel, what I’ve done it was to install a binary of PHP that homebrew brings to users of this operating system, if that is the issue what you are going through, perhaps this article could be useful for you. But in this time, I gonna show you guys a method that enhances the development experience, just installing a light virtual machine that I’ve found couple hours ago, which, from my perspective, it is an awesome way to develop apps with the Laravel framework as only you need to work in your favourite IDE with no need to sync anything to the server, since, this one is responsible to manage your project’s files automatically, and of course you can use it with any development framework you see out there.
Let’s prepare our boxes
First off, we must understand that a virtual machine is a functional guest operating system within another one called as a host, which it shares resources of the software and hardware in two-ways. Please do not confuse this concept of a machine with a bunch of gears around a headset of virtual reality, instead of that, notice there are two kinds of virtual machines: those are of system, and the other one are of process. Clearly I’m talking about system, which it means they are machines with a system is emulated within a host.
In order to get it better, I’d like explain it by following way:
Everything on the guest works in the same way as if is working in a physical computer with the difference the host is sharing its own resources for the guest os.
There are many software to emulate a fully functional operating system; virtualbox and vmware are a few of them, so in this case we’re going to download the first one because is free and for reasons of this exercise is convenient, just go ahead and download it, grab the correct version for your installed operating system and download this other one in order to comunicate with the virtual machine which this last one allow us to install an operating system with needed software pre-installed and pre-configured.
Grabbing out the system for development
As you see here, you can see Laravel’s guys want to make its development more easier and less painful with annoying settings, so that’s why they provide us a git repo where we can grab its virtual machine for vagrant pre-configured already, so, you need to type in the terminal this command:
$ vagrant box add laravel/homestead
in order to add the basic installation of the system where laravel will work.
Now you need to clone its git repo inside of your $HOME:
$ git clone https://github.com/laravel/homestead.git Homestead
Consider adding an ssh key for the virtual machine like this:
$ ssh-keygen -t rsa -C "firstname.lastname@example.org"
Once you’ve cloned the repo, you need to do a
bash init inside
Homestead folder created and you’ll see a message that it says
Homestead is initialized or something like that.
Now you’re going to configure your apps in the
Homestead.yaml located under
Go back to the Homestead cloned folder and type
vagrant up; it’ll start to get the operating system and configure according to the Laravel environment automatically.
Consider read the laravel page that I’ve provided you, so you can understand well what parameters you need to configure according to your app
Only have to do is edit the
/etc/hosts file in order to associate the ip of the virtual machine to a name you want type from your browser
And you’re done! you’re ready to develop locally your apps with a functional virtual machine that you can access via
vagrant ssh inside of the Homestead folder.
As a recommendation I can give you, if you want to access to the mysql server, notice you need to do through SSH Tunnel, considering to put your ssh key instead of a password like this:
MYSQL HOST: 10.0.2.15 Username: homestead Password: secret ------------------------ SSH HOST: ip address that you put in the ~/.homestead/Homestead.yaml SSH USER: vagrant SSH Password: ~/.ssh/id_rsa SSH PORT: Leave empty