In the last 3 years, I had mad a few steps in developing. In the very first days, I had uploaded files with ftp or sftp on the server. After one year I had my first big job in a little team and that was the first time I heard about version control. It sounds crazy, but I never had imagine that there were tools around coding that can bring you such a big benefit. And now, there are that much tools around coding. A good developer has to know so much about things like pipelining, version control, frameworks, desing patterns, testing, security and much more stuff. And today I want to check an other little thing. Vagrant. First I heard about it from Danilo Braband. He made a cool presentation about it, but I was a little bit critical. I thought:"I didn't need more fancy tools, I guess I can live without it". But a few weeks later, I did see more and more little Vagrantfiles on github and in practice it's very efficiently . And today I want to make my own first steps with vagrant.
Vagrant is a tool for building complete development environments. It gives you the possibility to work as near on the same conditions of your production-server. And you can create and destroy it in minuts and share a Vagrantfile in your repository for other developers.
This isn't a tutorial. Cause all I'm writing here, is based on the documentation of vagrent. All I do, is to write a post about my first steps of using this tool. This post is more like a little bad copy of the documentation.
Let's change to your project directory and initialize the directory for usage of vagrant. My new project has the name waman and is under /var/www.
This should create a file named Vagrantfile in your directory.
cd /var/www/waman vagrant init
Now can we add a box to vagrant with.
This is Ubuntu 12.04 LTS 32-bit. But here is a list of other boxes. Please note, this isn't supported by vagrant project. Let's use our box. Currently is your Vagrantfile full of comments. You can remove the comments, but please change line
vagrant box add precise32 http://files.vagrantup.com/precise32.box
config.vm.box = "base"
Without comments should our Vagrantfile like this.
config.vm.box = "precise32"
Vagrant.configure("2") do |config| config.vm.box = "precise32" end
You can start the box with the following command.
You can get ssh connection with the command.
With the command
we can change to the syncron directory. It's the same directory from our project. Let's leave the box and destroy it.
We want to install apache on your box. First we have to build a shell-script in your directory, bootstrap.sh.
and edit Vagrantfile
apt-get update apt-get install -y apache2 rm -rf /var/www ln -fs /vagrant /var/www
Now we can start the box again.
Vagrant.configure("2") do |config| config.vm.box = "precise32" config.vm.provision :shell, :path => "bootstrap.sh" end
If we connect with ssh, we can check if apache is running.
Let's exit the box and set up the network. We edit the Vagrantfile like this.
vagrant ssh wget -qO- 127.0.0.1
and reload the box
Vagrant.configure("2") do |config| config.vm.box = "precise32" config.vm.provision :shell, :path => "bootstrap.sh" config.vm.network :forwarded_port, host:8080, guest:80 end
Now we have access over the browser with 127.0.0.1:8080. That was a little summary of the vagrant documentation. Here is the next part of my first steps with vagrant.