Home  >  Article  >  php教程  >  VirtualBox + Vagrant (Mac/Win/Linux unified development environment)

VirtualBox + Vagrant (Mac/Win/Linux unified development environment)

WBOY
WBOYOriginal
2016-08-04 08:56:25991browse

In team development, everyone has their own integrated environment, such as WAMP, AppServ, and There is no problem running on it”. So the question is, how to solve this problem?

How to unify the development environment?

Vagrant is a tool used to build a virtual development environment. We can use Vagrant to encapsulate a Linux development environment and distribute it to team members. Members can develop programs on their favorite desktop system (Mac/Windows/Linux), but the code can be run uniformly in a packaged environment, which is very domineering and cool to use.

Vagrant’s best friend

VirtualBox: Claimed to be the most powerful free virtual machine software similar to VM.

Not only is it rich in features, but its performance is also excellent.

How to install?

1. Install VirtualBox:
Website: https://www.virtualbox.org/wiki/Downloads

2. Install Vagrant:
URL: http://downloads.vagrantup.com/

3. Download system image:
Website: http://www.vagrantbox.es/

Just install them one by one in order~

Specific operations

1. Add image to Vagrant:

The image is stored in /home/box/centos65.box

cd/home/box/

vagrant box add centosbox centos65.box

2. Initialize the development environment:

vagrant init centosbox #Initialization

vagrant up #Start environment

3. SSH login:

Use Xshell, Putty, SecureCRT, etc. to log in.

IP: 127.0.0.1

Port: 2222

Username: root

Password: vagrant

Commonly used configurations

After Vagrant is successfully initialized, a Vagrantfile will be generated in the initialization directory, which can be modified for personalized customization.

1. Configure IP:

config.vm.network :private_network, ip: “192.168.33.10”[remove #]

You can change the IP to another address as long as there is no conflict.

2. Configure the synchronization directory:

config.vm.synced_folder “../data”, “/vagrant_data” [remove # and modify it to the following]

config.vm.synced_folder “/home/web/www”, “/data/www“

/home/web/www: local directory
/data/www: Linux server directory

3. Configure virtual memory:

Add the following paragraph before the end character of the file:

config.vm.provider :virtualbox do |vb|

vb.customize ["modifyvm", :id, "--memory", "2048"]

end

Warm reminder: Remember to restart the virtual machine after modifying the configuration.

Package and distribute

When you have configured your development environment, exit and shut down the virtual machine.

Package the development environment in the terminal:

vagrant package

After packaging is completed, a package.box file will be generated in the current directory,

Pass this file to other users,

Other users only need to add this box and use it to initialize their own development directory,

You will get an identical development environment.

Commonly used commands

vagrant init #Initialization

vagrant up #Start the virtual machine

vagrant halt #Close the virtual machine

vagrant reload #Restart the virtual machine

vagrant status #View virtual machine running status

For more [dry information sharing], please pay attention to the PHP engineer subscription account.
VirtualBox + Vagrant (Mac/Win/Linux unified development environment)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn