Setting up my development environment with Vagrant

Setting up my development environment with Vagrant


I’ve changed jobs quite often due to various reasons. I’ve never seen or been to a company where a developer joins, and the on-boarding experience is, here’s your laptop, we’ve installed everything that you need to do your work. Get cracking. If I ever joined a company like that, I’d probably get a minor stroke.

shocked-catHOW DARE THEY FORCE ME TO USE VISUAL STUDIO!
BLASPHEMY!

So the most important thing to do before getting funky with the codes is setting up the development environment. Here’s the list of stuffs that I do to setup the development environment on a newly assigned PC/Laptop (excluding IDE).

Stuffs that I need initially is, Chocolatey, VirtualBox, Vagrant & MinGW.

1. Installing Chocolatey & Other Packages.

Windows do not have a package manager. This is the next best thing (unless there’s something newer that I’ve never heard about). There are several ways to install chocolatey but the one that I often use is the first one.

Open up a CMD prompt and run it as an administrator.

gettingstarted1

Then you’ll end up something like this.

 

gettingstarted2

After having a CMD prompt with administrator privilege, install Chocolatey.

gettingstarted2-1

After installing chocolatey, refresh the environmental variables. There is no easy way or a single line command that can be done (for now) that I know of. So, close the command prompt and reopen it again (run as administrator, refer above). After running the cmd prompt, you can type in choco to view the installed version of chocolatey.

Now chocolatey is installed, I need to install all the other stuffs to continue.

gettingstarted3gettingstarted4gettingstarted5

When all three of the above software is installed, refresh the environmental variables (close and reopen cmd prompt, this time we dont need the administrator privileges).

2. Setting up the VM with Vaprobash

Clone (or as an svn user would like to call it, checkout) Vaprobash. Its the simplest provisioning script for vagrant that I have used.

After cloning it, there’s a file in the folder called Vagrantfile, open it up with a text editor. The softwares that I usually use is PHP (already uncomment), Vim (line 209), Apache (line 219), MySQL (line 230), NodeJS (line 318) and Composer (line 332). So from the Vagrantfile, uncomment those lines.

Now, I need to define a folder that I want to be synced with the guest VM. Put it below line 127.

Next, define a port to be forwarded for the virtualhost to use, should be below line 117.

That should be it for the Vagrantfile modifications. Start up the vm with vagrant up.

To test if the sync folder is working, if the files in D:/work is listed in /var/www, its working. Or you can create a file in the shell,

Going to D:/work using Windows Explorer, if the sync is working, there would be a file called testfile in it.

3. Setting up Apache Virtualhost

Now we have vagrant all ready. Lets get into it with vagrant ssh.

gettingstarted6

First we need to create the virtualhost by creating another conf file. This new conf file will be based from 000-default.conf. Copy 000-default.conf

Open up the file and edit it (never used vim? LMGTFY)

There will be quite a lot of comments in it but the gist of the file should be

Save the file!

Now is the time to enable the configuration and restart apache2.

Apache should be listening to that port now. To see if it really is listening to it, use netstat.

e.g. in my VM it displays like this (I use port 7004 with Nginx).

gettingstarted7

So now you have your guest OS listening to 7001, your host OS listening to 8001. Everything is ready. Put your project in D:/work/mynewproject and open up http://localhost:8001 in your browser.

 

References

 

+ There are no comments

Add yours