I’m a big fan of Laravel and I’ve really enjoyed building things on it. So I’m going to walk you through a quick lesson in getting a dev environment set up.
Setting up Local DNS
A good first place to start is setting up local DNS. In my case, I use the *.dev
TLD for my local projects. Rather than reproduce all the steps, I will instead point you at this very good guide on using DNSMasq on OS X.
The one thing to note is that, when it mentions pointing your domain to 127.0.0.1, you instead need to point it to 192.168.10.10. This is the local address for the Homestead virtual machine.
address=/dev/192.168.10.10
Setting Up Homestead
Sites
One of the neat things about Laravel is Homestead, a virtual machine ready to go with all you need to get you up and going as quickly as possible. But, one of the things I don’t like about it is that you either have to have multiple virtual machines for each laravel project (which wastes space) or manually enter each one. So you end up with something like this.
This repetition is unnecessary. If you follow the same format and put all your Laravel projects in the same location, you can do something like this instead:
Now, going to llama.dev
will direct you do the code in /home/vagrant/Development/llama/public
. Easy!
Databases
But what about databases? Well there’s a solution for this too. In your homestead directory, edit the after.sh
file like this:
This little script will read the .env
file in each of your Laravel directories and, if the database doesn’t yet exist, it will create it. So any time you need to create a new project, just re-run vagrant provision
.
Conclusions
Now, starting a new Laravel project is as easy as issuing just a few commands:
laravel new blog
Edit the .env
as needed.
cd ~/Homestead;
vagrant provision
And you’re ready to start coding.