Vagrant for Full Stack Web Development

What a fresh day ! Been in setting up back my vagrants on each boxes I love , ror , php and plus nginx. For those who don’t heard about Vagrant , here is the [brief] http://www.vagrantup.com/about.html.

Vagrant can give you a lot of automations and software independent development environment. You don’t need to mass around with xampp,mampp or similar solutions that you ever used in your full stack development.

So how do we install ? You need Virtual Box pre-install in your working machine coz vagrant use VM box technology. Here is the official [instruction] http://docs.vagrantup.com/v2/getting-started/index.html.

And you are up to go. Add a VM image and up. Simply

Install Script
1
2
vagrant init precise32 http://files.vagrantup.com/precise32.box
vagrant up

Do you want primative OSs then ubuntu ? Ok you can get a list of Boxes for Vagrant on hand. But you need to import the image into VM first or you can add via url option before you initiate the vagrant. Simply

Box List
1
vagrant box list

After initiating vagrant you will get a minifest file and you can modify the behavoir of your vagrant box. First of all the networking is important. Edit the file with your favorite software.

And you will see the imported box_url configuration and network options for your box.

A Look at Vagrantfile
1
2
3
4
5
6
7
8
  # The url from where the 'config.vm.box' box will be fetched if it
  # doesn't already exist on the user's system.
  config.vm.box_url = "http://files.vagrantup.com/precise32.box"

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  config.vm.network :forwarded_port, guest: 80 , host: 8080

Install your favorite webserver and in my case I install apache2. Make ssh into your vm box using vagrant command.

Install Apach
1
2
3
4
5
6
Tin-Aung-Lin~$ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
  * Documentation:  https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:22:31 2012 from 10.0.2.2
vagrant@precise32:~$ sudo apt-get install apache2

And just test with curl from your terminal whether network between your host and vm box work or not.

Check
1
curl localhost:8080

If you have done the above guides nicely , you will get a default Apache response back.Now you can configure your box as your VPS management style right where on your machine.

After you have done configuration and setting up development requirements , you can share the vm box with your friends to use as their vagrant box.

[ Synced Folders ]

Oh , yeah. It is insanely cool that you can update the source codes from your host machine rather than in the box. So we can use whatever we like to. Usually the Synced Folder means the folder enclosing the Vagrantfile of current running box. You can configure your webserver’s document root to this synced folder in your box.

Set Document Root
1
2
3
4
5
6
Tin-Aung-Lin~$ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
  * Documentation:  https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:22:31 2012 from 10.0.2.2
vagrant@precise32:~$ cd /vagrant

That is it . The folder “/vagrant” is synced with your Vagrant directory.

Had Fun

Tin Aung Lin

Copyright © 2016 - Tin Aung Linn. Powered by Octopress