工欲善其事 its prerequisite, development environment and development tools are the swords of our developers, so we need a quick and easy-to-use sword
.
Just started to do the development of the time is to configure the development environment in their own computer, with the things we touch more and more, slowly computer are all kinds of environment, php,java,python,nodejs and so on, very troublesome, and often for some reason put the computer re-installed, ORZ, So the environment has to be back again. So it's very important to create an environment that is self-moving.
Vagrant is a built-in virtual development environment tools, support WINDOW,LINUX,MAC, there is always a suitable for you. And vagrant can be configured to package the environment into a box, sharing to other people directly use, very convenient
System Requirements: (I mac System)
The machine supports virtualization, and sometimes requires tuning the BIOS to turn on CPU virtualization.
First step: Install VirtualBox (i VirtualBox version 4.3.30)
Please download the specific installation package directly from the official website: https://www.virtualbox.org/wiki/Downloads
Step Two: Install vagrant (I vagrant version vagrant 1.6.3)
$ vagrant-vvagrant 1.6.3 Specific installation package please download directly from the official website:
Step three: Vagrant basic Commands (Official documents: https://docs.vagrantup.com/v2/getting-started/index.html)
Vagrant init initialization vagrantfilevagrant Add box, automatically generates vagrantfilevagrant halt for you to turn off virtual machine vagrant destroy Destroy virtual machine vagrant SSH connect virtual machine vagrant Reload Reload vagarntfile file vagrant suspend temporarily suspend virtual machine vagrant Status View virtual machine run-like State
Fourth Step: Sample Demo
4.1 Download Box
Here are the two official addresses of Ubuntu:
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/
$ mkdir-p ~/vagrant/boxes$ CD ~/vagrant/boxes && wget $ vagrant Box Add Ubuntu64 precise64.box//Add Box
4.2 Create a new Lnmp (Linux + nginx + mysql + php-fpm) virtual machine
$ cd ~/vagrant && mkdir lnmp$ cd lnmp$ vagrant init ubuntu64//Initialize $ vagrant up//start virtual machine lnmp$ vagrant SSH//Enter virtual machine LNM P
This virtual machine is new, is not soon!! If you are familiar with Linux, you can modify the source and install the software.
$ sudo apt-get install keychain nginx mysql-server mysql-client php5-cli php5-fpm php5-gd php5-mysql
the specific process can also refer to my blog:ubuntu12.04 installation php5.4/php5.5
Fifth step: Personalized configuration Vagrantfile
After Vagrant Init we will find a vagrantfile file in the corresponding directory.
Directly on, not one by one explained
Sixth step: Export your own box
$ cd ~/virtualbox\ vms/phponubuntu64$ vagrant package--output Lamp5_5onubuntu64.box--base phponubuntu64
Precautions
Problem one) 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:
#nginx配置
Sendfile off
#apache Configuration
Enablesendfile off
Issue two: Start multiple virtual machine prompt error "2222 port in use"
Workaround: (Reference article: Vagrant SSH errors with multiple vms:port 2222 on use)
Config.vm.network "Forwarded_port", guest:22, host:2220, id: ' SSH '
Question three: If you encounter PHP code also feel cached, please close Apc,opcode (from php5.5 and later version by default opcode)
Original address: Quickly build your own development environment vagrant + VirtualBox
Quickly build your own development environment vagrant + VirtualBox