Linux Development under Windows: Leveraging Vagrant+virtualbox

Source: Internet
Author: User

1, Introduction vagrant

When we do web development, we often have to install a variety of local test environment, such as Apache,php,mysql,redis and so on. For personal use, maybe we are still more accustomed to using Windows. While it is possible to build a variety of development environments under Windows, there are versions of Windows in every major development environment. However, configuration under Windows can sometimes be cumbersome and can cause inconsistencies in the development environment (Windows) and production environments (LUnix).
Can it be developed under Windows as well as Linux? Maybe you think of it with a virtual machine. It would be nice to install a Linux system with a virtual machine. Install the Linux system, set up a shared directory, set up network port mappings, and so on. It seems to be a little cumbersome.
Also, if we are a team to develop, then everyone on the computer to install a virtual machine + Linux system + various operating environment. Manual setup Trouble not to say, everyone's development environment is not very consistent (maybe you installed Apcahe i installed Nginx, etc.), but also a headache. Can you automate all the settings and keep the entire team in a consistent development environment?
Vagrant was born to solve the problem. It uses open source VirtualBox as virtualization support and can be easily deployed across platforms.

2, download

Download Virtualbox:http://download.virtualbox.org/virtualbox/4.3.28/virtualbox-4.3.28-100309-win.exe
The above gives a download link for version 4.3.28. To download a different version, visit the official website https://www.virtualbox.org/wiki/Downloads

Download vagrant:
Https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2.msi
The above gives a download link for version 1.7.2. To download a different version, please visit our website
Http://www.vagrantup.com/downloads.html

To download a virtual image:
Https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box

The above gives the centos-6.6 image download link, to download other images please visit the official website
http://www.vagrantbox.es/

3, installation

Once you have downloaded the above package, install VirtualBox and install vagrant. are both double-click to install (the installation is independent of each other), so there is no good introduction. The following describes how to import the image.
Create a new working directory first
Like I built a new d:vagrantworkcentos-6.6-x86_64.
Open the cmd command prompt, go to the new directory, take my list above as an example, enter

        D:        cd D:VagrantWorkcentos-6.6-x86_64

Then enter command initialization

vagrant init centos6.6

Copy the downloaded Centos-6.6-x86_64.box to this directory d:vagrantworkcentos-6.6-x86_64, execute

vagrant box add centos6.6 centos-6.6-x86_64.box

Check whether the import was successful

vagrant box list

4, configuration

Use a text editor to open the Vagrantfile file in the d:vagrantworkcentos-6.6-x86_64 directory to make some common configurations.
A few common configurations are listed below. To use the other configuration please visit the official website of the document or Baidu Google a bit.
1, port mapping

config.vm.network :forwarded_port, guest: 80, host: 8080

Remove the # number in front of the above code. It represents a 8080 port mapping native to the 80 port of the virtual machine
2, if you need free access to the virtual machine, but others do not need to access the virtual machine, you can use Private_network, and set the IP for the virtual machine.

config.vm.network :private_network, ip: 192.168.33.10

Remove the # number in front of the code above
3, Directory Mapping

config.vm.synced_folder "D:/www", "/var/www/html"

If the above command is enabled, it means that the data directory of the machine is shared to the/var/www directory in the virtual machine.

5, start

Execute command after entering directory d:vagrantworkcentos-6.6-x86_64

vagrant up

After the virtual machine starts, it can be vagrant ssh into the virtual machine for further environment configuration, or software installation related work, under the Windows system, and not directly through the vagrant SSH connection to the virtual machine, need to use Putty,xshell and other third-party tools to connect. Connection address 127.0.0.1, Port 2222. Login account root password is vagrant

6, Export

After executing the working directory in CMD, execute the following command

vagrant package

Once completed, Package.box will be generated in the current directory and then the new virtual machine can use this box. If you set up a variety of development environments in your virtual machine beforehand, you can install the box directly to the other members of your team, eliminating the time it takes to deploy a single computer and keeping the development environment consistent. Very convenient to have wood there.

7, other commands

The following is a list of some common cmd operation commands
Vagrant Up (Start virtual machine)
Vagrant Halt (Turn off the virtual machine-the corresponding is the shutdown)
Vagrant Suspend (Pause virtual machine-just pause, virtual machine memory and other information will be saved locally as a state file and can continue to be used after a recovery operation)
Vagrant Resume (restores the virtual machine-corresponds to the previous pause)
Vagrant Box Remove centos6.6 (remove box, where centos6.6 is the box name)
vagrant destroy (Deleting a virtual machine, deleting the configuration in the current virtual machine that is done except for Vagrantfile is not retained)

Linux Development under Windows: Leveraging Vagrant+virtualbox

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.