DEV Community

aurel kurtula
aurel kurtula

Posted on

Setting up Virtual Box, Vagrant and Scotch Box

As I said in my previous post I had to get a new Macbook after my old one braking down. As a result I had to reinstall everything from scratch. Up to now everything is going very smooth.

The following is just an explanation on how I managed to install Virtual Box, Vagrant and Scotch box. More as a note to self than anything else

First install Virtual box

Then install Vagrant

As you'll see both installations are done by clicking continue/next.

To test whether the above are correctly installed you can open virtualbox as an application.

If you see something like the above, you know it has installed correctly. (You'll not need to use it, vagrant is going to work with virtualbox).

To test if vagrant was installed correctly run vagrant -v in terminal.

Installing a box

After the above, all you'd need to do is install boxes. These self contained virtual boxes that you can run in your local computer but treat as if they are separate.

So far I have only tried Scotch Box is "the perfect and dead simple LAMP/LEMP stack for local development"

As shown in their home page this box can easily setup.

Go in your preferred folder and run

git clone https://github.com/scotch-io/scotch-box 0006.scotch-box-setup-test
cd 0006.scotch-box-setup-test
Enter fullscreen mode Exit fullscreen mode

Inside that folder you'll see the following file

As you can imagine we would add our work inside the public folder - replacing the index.php with anything you'd want.

In terminal, inside my-project you'd finally run

vagrant up 
Enter fullscreen mode Exit fullscreen mode

Now if you visit http://192.168.33.10/ you'll see the 0006.scotch-box-setup-test/public/index.php rendered on the page. You can edit the file, then refresh the browser to see the changes.

Interesting things to note

Whilst you don't need to ever open the Virtual Box application, if you do open it now, you'll see a box with your folder name running

Similarly, you can run vagrant halt which turns the box off, and in the virtual box application you'll see the indication of "Powered off" where now it says "Running".

As you can see, you're able to control the boxes via the terminal so you never need to open the virtual box app.

Second thing that I think is extremely important to note is that the first time you run vagrant up on a Scotch Box project, a virtual box is installed in your computer, it's located at /Users/{username}/VirtualBox VMs (on windows, most likely it's at C:\Users\{username}\VirtualBox VMs) . One scotch box is 3.52 GB. So the idea that you should install one box for every web project you want to work on seems to be an over kill.

Conclusion

I'm so happy that I was able to set this up! I tried it once before (in my old MacBook) and things went really wrong. But now it all works like a charm.

I do believe scotch box is an overkill for what I need. It offers Node and MongoDB for example and yet all I want to do on a virtual box is PHP development! However, to get started, this was amazingly simple.

In my next post I'll try to document how we could create a website using this setup!

There are a lot of other vagrant boxes, I wonder if anyone could leave a comment on which is the best box for PHP development without the extras provided by scotch box - thanks

Top comments (0)