A tutorial on installing Cross-platform Team development tools Vagrant Linux Systems

Source: Internet
Author: User
Tags php framework ssh virtual environment

Vagrant is a tool to create lightweight, highly reusable, and portable development environments.
In the eyes of the non-professional, this means that vagrant discard all the headaches in the development environment for a single configuration file, you can choose the features you need for your server to keep. You will no longer be XAMMP, manually configure the virtual environment, or use the FTP remote edit card.
Vagrant is a powerful tool, and its function and value are beyond the scope of this article and my understanding can reach. This article will introduce some pretty cool things in vagrant, such as:
Use the PHP5.4 version of lamp in your machine.
How to access the database conveniently in your virtual machine.
How to automatically update your hostfile, using a URL to reference a virtual server (developing on http://localhost:8080 versus http://myprojectname.local).
Some of the necessary vagrant commands.
The best and most useful vagrant plug-ins.
Links to more resources and pre-built vagrant stacks.

Imagine that you are developing an application with a team of supposedly 15 people. This program is really awesome! It uses the Laravel PHP framework, Redis and Memcached,imagemagick and GD's PHP modules, Curl,mysql and PostgreSQL, and even MongoDB. In addition, Laravel explicitly relies on PHP versions 5.3.7 or later, and mcrypt PHP extensions.
Ideally, you would want all 15 people in the team to develop the application in the same development environment. But not all development teams have systems management expertise or a system management. Getting the same set of development environments can be a daunting task. Most importantly, some people use a Mac, while others use Linux or Windows. Before it, developers struggled with the endless configuration of throwing a computer at a wall and exhausted.

Vagrant will help you manage all the settings for your environment so that you can focus on the development of your business code.
To look at a scenario, the project developed a half to discover the need to install BEANSTALKD to handle queue problems. Typically, people will stop to reconfigure the environment and expect the Bean STALKD to function properly. With vagrant, just push the update file to the configuration file, and all you need to do is refresh the vagrant. That's great! Then you can use the queue function. This has nothing to do with operating systems, whether it's Windows, Linux, or Mac, because everyone's operating environment is the same.

Installation steps

1. Install VirtualBox
The virtual machine still has to rely on VirtualBox to build, free small.
Download Address: Https://www.virtualbox.org/wiki/Downloads
* Although Vagrant also supports VMware, VMware is charged and the corresponding vagrant version is also charged
2. Install vagrant
Download Address: http://downloads.vagrantup.com/Follow the prompts to install step-by-step.
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 a mirror image of another system, you can download it here: http://www.vagrantbox.es/
* In view of the domestic network speed, we will download the image of the steps separately stripped out
3. Add Mirrors to vagrant
Suppose we download the mirrored storage path is ~/box/precise64.box, enter in the terminal:

The code is as follows:
$ vagrant Box Add hahaha ~/box/precise64.box

Hahaha is our name for this box, ~/box/precise64.box is the path to the box.
4. Initialization of the development environment
Create a development directory (for example: ~/dev), you can also use the existing directory, switch to the development directory, with hahaha mirroring initialization of the current directory environment:

The code is as follows:
$ cd ~/dev # Toggle Directory
$ vagrant init hahaha # initialization
$ vagrant Up # Start environment

You will see that the terminal shows the boot process, when 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 that you want to run in the virtual machine.

The code is as follows:
$ 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 user Note: 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
Once the vagrant is initialized successfully, a vagrantfile configuration file is generated in the initialized directory, and the configuration file can be modified for personalized customization.
Vagrant default is to use port mapping to map the port of a virtual machine to achieve similar http://localhost:80 access, which is troublesome, new open and modify the port when all have to edit. In comparison, the host-only model seems more convenient. Open Vagrantfile, remove the comments from the following line (#) and Save:

The code is as follows:
Config.vm.network:p rivate_network, IP: "192.168.33.10"

Restart the virtual machine so that we can use 192.168.33.10 to access the machine, you can change the IP to another address, as long as there is no conflict on the line.
6. Packing and distributing
When you have configured your development environment, quit and shut down the virtual machine. To package the development environment in a terminal:

The code is as follows:
$ vagrant Package

After the package is completed, a Package.box file is generated in the current directory, which is passed to other users, and other users can get an identical development environment by adding the box and initializing their own development directory.
7. Common commands

The code is as follows:
$ vagrant Init # Initialization
$ vagrant Up # start virtual machine
$ vagrant Halt # Shut down virtual machines
$ vagrant Reload # restart virtual machine
$ vagrant SSH # SSH to virtual machine
$ Vagrant Status # View virtual machine running status
$ vagrant Destroy # Destroy the current virtual machine

For more information, please check the official documentation http://docs.vagrantup.com/v2/cli/index.html
8. Matters needing attention
When you use Apache/nginx, a situation such as a picture modification, but the page refresh is still an old file, is caused by a static file cache. The Apache/nginx configuration file in the virtual machine needs to be modified:

The code is as follows:

# Apache Configuration add:
Enablesendfile off
# Nginx configuration add:
Sendfile off;
The Segmentfault team is the

that unifies the development environment in this way.

Related Article

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.