Vagrant How to use

Source: Internet
Author: User

  



0. Introduction
Vagrant is a tool for building a virtual development environment that is ideal for developing Web applications in languages such as Php/python/ruby/java, which is a history of "code running on my machine without problems".
We can package a Linux development environment through Vagrant and distribute it to team members. Members can develop programs on their favorite desktop system (Mac/windows/linux), but the code can be unified in a packaged environment to run, very domineering.
1. Installation procedure 1. Installing VirtualBox

Virtual Machine VirtualBox Free Compact
:https://www.virtualbox.org/wiki/Downloads
  * Vagrant also supports vmware,vmware charges, the corresponding Vagrant version is also charged

2. Installing Vagrant

:http://downloads.vagrantup.com/ Follow the prompts step by step installation.

In addition, you have to download the official encapsulated base image:

Ubuntu precise VirtualBox http://files.vagrantup.com/precise32.box

Ubuntu precise VirtualBox http://files.vagrantup.com/precise64.box

If you want to mirror other systems, you can download them here:http://www.vagrantbox.es/

  * In view of the domestic speed, we separate the steps to download the image separately.

3. Add image to Vagrant

Suppose we download the image storage path is ~/box/precise64.box, in the terminal input:

$ vagrant Box Add hahaha ~/box/precise64.box

Hahaha is our name for this box, ~/box/precise64.box is the path to the box.

4. Initializing the development environment

Create a development directory (for example: ~/dev), you can also use the existing directory, switch to the development directory, with the HAHAHA image to initialize the current directory environment:

$ cd ~/dev # switch Directory

$ vagrant init hahaha # initialization

$ vagrant Up # boot environment

You will see that the terminal shows the start-up process, and after the boot is complete, we can login to the virtual machine with SSH, and the rest of the steps are to configure the various environments and parameters you want to run in the virtual machine.

$ vagrant SSH # SSH Login

$ cd/vagrant # Switch to the development directory, which is the ' ~/dev ' on the host

The ~/dev directory corresponds to the directory in the virtual machine/vagrant

Windows users Note: The Windows terminal does not support SSH, so you need to install a third-party SSH client, such as: Putty, Cygwin and so on.

5. Other Settings

After the Vagrant initialization succeeds, a vagrantfile configuration file is generated in the initialized directory, which can be customized by modifying the configuration file.

Vagrant default is to use port mapping to map the port of a virtual machine locally to achieve a similar http://localhost:80

This kind of access, this way is more troublesome, the new open and modify the port when you have to edit. In comparison, the host-only mode appears to be much more convenient.

Open the Vagrantfile and remove the comment from the line below (remove #) and Save:

Config.vm.network:p rivate_network, IP: "192.168.33.10"

Restart the virtual machine so that we can access the machine with 192.168.33.10, you can change the IP to another address as long as there is no conflict on the line.

6. Packaging and distribution

When you have configured your development environment, exit and shut down the virtual machine. To package the development environment in the terminal:

$ vagrant Package

When the package is complete, a Package.box file is generated in the current directory, and the file is passed on to other users, and other users simply add the box and initialize their development directory to get an identical development environment.

7. Common commands

   $ vagrant init # initialization

$ vagrant Up # to start a virtual machine
$ vagrant Halt # shutdown Virtual machine
$ vagrant Reload # restart virtual machine
$ vagrant SSH # SSH to virtual machine
$ Vagrant Status # View virtual machine health status

$ vagrant Destroy # destroys the current virtual machine

  

For more information, please refer to the official documentation:

http://docs.vagrantup.com/v2/cli/index.html

8. Precautions

The use of Apache/nginx will appear after the changes in the film, but the page refresh is still an old file, due to the static file cache. The Apache/nginx configuration file in the virtual machine needs to be modified:

# Apache Configuration add: Enablesendfile off# Nginx Configuration add:

Sendfile off;



From for notes (Wiz)

Vagrant How to use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.