Using Vagrant on Windows to create a LaravelHomestead collaborative cross-platform development environment

Source: Internet
Author: User
Tags ssl certificate
Creating a LaravelHomestead collaborative cross-platform development environment using Vagrant on Windows

Everyone is familiar with VMware or VirtualBox, and the benefits of virtualization are naturally deeply rooted in the hearts of the people. now we can build a complete development environment similar to Laravel Homestead through Vagrant, this greatly reduces the time required to set up the development environment. It also supports sharing custom packages on different Windows, Mac, and Linux platforms, and unifying the development environment between teams to improve work efficiency, the emergence of Docker makes the future even more worth looking forward.

Use Vagrant to create a wonderful cross-platform development environment

Update History

April July 18, 2015-First Draft

Http://wsgzao.github.io/post/vagrant/

Additional reading

Vagrant-https://www.vagrantup.com/
Laravel Homestead http://laravel.com/docs/5.1/homestead
Linux development in windows: using Vagrant + virtualbox-http://blog.star7th.com/2015/06/1538.html
Use Vagrant on Mac/win7 to build a local development environment-http://segmentfault.com/a/1190000002645737

Environment preparation
  1. Git (not required)
  2. PHP (not required)
  3. Laravel (not required)
  4. Composer (not required)
  5. Vagrant
  6. VirtualBox

If you need offline installation, please leave a message and reply.

Install git

1. download GitHub for Windows

Https://windows.github.com/

Install php

We recommend that you install the latest PHP version whenever possible.

1. Download PHP

Http://windows.php.net/download/

2. decompress the Directory

My path D: \ php

3. add environment variables

Right-click computer> Advanced System Settings> environment variables> System variables> PATH

C: \ ProgramData \ Oracle \ Java \ javapath; % SystemRoot % \ system32; % SystemRoot % \ System32 \ Wbem; % SYSTEMROOT % \ System32 \ WindowsPowerShell \ v1.0 \; c: \ nodejs \; D: \ php; C: \ ProgramData \ ComposerSetup \ bin

4. set php. ini

Enter the PHP installation directory (for example, D: \ php ). Find the php. ini-development File, copy it to the current directory, rename it php. ini, and modify the following configuration.
Remove the semicolon before extension = php_mbstring.dll (about 888 rows)
Remove the semicolon before extension = php_openssl.dll (about 893 rows)
Remove the semicolon before extension_dir = "ext" (about 736 rows)

5. make environment variables take effect

Restart assumer.exe

Install Laravel

1. download Laravel

Http://www.golaravel.com/download/

2. decompress the Directory

My path D: \ laravel-v5.1.4

3. start Laravel

d:cd laravel-v5.1.4D:\laravel-v5.1.4>php artisan serveLaravel development server started on http://localhost:8000/

Access http: // localhost: 8000/in a browser/

The serve command of artisan also supports two parameters:

Host setting host address
Port: Set the port number of the web server listener.
Example: php artisan serve -- port = 8888

Install Composer

1.download composer-setup.exe

Https://getcomposer.org/doc/00-intro.md#installation-windows

2. configure Composer

Loading composer repositories with package informationInstalling dependencies (including require-dev)SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed”

If the CA certificate is missing during installation, download cacert. pem to the custom path.
Http://curl.haxx.se/docs/caextract.html

Then modify the php. ini file (about 1983 lines)

Openssl. cafile = D: \ php \ verify \ cacert. pem

3. test Composer

composer -VComposer version 1.0-dev (d79427f1a7b15e8f4d46ce8124a4d0c58ba1479c) 2015-07-04 11:22:58
Install Vagrant

1. download Vagrant

Https://www.vagrantup.com/downloads.html

2. download the virtual image offline

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

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

Install VirtualBox

Enable CPU hardware Virtualization in BIOS to support VT (Virtualization Technology)

1. download VirtualBox

Https://www.virtualbox.org/wiki/Downloads

2. import an image

Set VirtualBox directory and copy image centos-6.6-x86_64.box
E: \ VirtualBox \ centos-6.6-x86_64.box

3. command to initialize Vagrant

# Switch the VirtualBox directory e: cd. \ VirtualBox # enter the command to initialize E: \ VirtualBox> vagrant init centos6.6A 'vagrantfile' has been placed in this directory. you are nowready to 'vagrant up' your first virtual environment! Please readthe comments in the Vagrantfile as well as documentation on 'vagrantup. com 'for more information on using Vagrant. # execute the add command E: \ VirtualBox> vagrant box add centos6.6 centos-6.6-x86_64.box ==> box: Adding box 'centos6. 6' (v0) for provider: box: Downloading: file: // E:/VirtualBox/centos-6.6-x86_64.box box: Progress: 100% (Rate: 670 M/s, Estimated time remaining :--: --: --) => box: Successfully add Ed box 'centos6. 6' (v0) for 'virtualbox '! # Check whether the import is successful. E: \ VirtualBox> vagrant box listcentos6.6 (virtualbox, 0)
Vagrant configuration

For detailed configuration documentation, refer to the official manual-https://docs.vagrantup.com/v2/

Start Vagrant

Enter the directory E: \ VirtualBox through Shell and execute the command

 vagrant up

The complete process of smooth start is as follows:

E:\VirtualBox>vagrant upBringing machine 'default' up with 'virtualbox' provider...==> default: Importing base box 'centos6.6'...==> default: Matching MAC address for NAT networking...==> default: Setting the name of the VM: VirtualBox_default_1437213832296_68434==> default: Clearing any previously set forwarded ports...==> default: Clearing any previously set network interfaces...==> default: Preparing network interfaces based on configuration...    default: Adapter 1: nat==> default: Forwarding ports...    default: 22 => 2222 (adapter 1)==> default: Booting VM...==> default: Waiting for machine to boot. This may take a few minutes...    default: SSH address: 127.0.0.1:2222    default: SSH username: vagrant    default: SSH auth method: private key    default: Warning: Connection timeout. Retrying...    default:    default: Vagrant insecure key detected. Vagrant will automatically replace    default: this with a newly generated keypair for better security.    default:    default: Inserting generated public key within guest...    default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... default: The guest additions on this VM do not match the installed version of default: VirtualBox! In most cases this is fine, but in rare cases it can default: prevent things such as shared folders from working properly. If you see default: shared folder errors, please make sure the guest additions within the default: virtual machine match the version of VirtualBox you have installed on default: your host and reload your VM. default: default: Guest Additions Version: 4.3.28 default: VirtualBox Version: 5.0 ==> default: Mounting shared folders... default: /vagrant => E:/VirtualBox

After the virtual machine is started, you can connect to the virtual machine through vagrant ssh for further environment configuration or software installation. in Windows, you cannot directly connect to the virtual machine through vagrant ssh, use a third-party tool such as SecureCRT, Putty, and Xshell to connect. The connection address is 127.0.0.1 and Port 2222. The root password of the logged-on account is vagrant.

E:\VirtualBox> vagrant upBringing machine 'default' up with 'virtualbox' provider...==> default: Clearing any previously set forwarded ports...==> default: Clearing any previously set network interfaces...==> default: Preparing network interfaces based on configuration...    default: Adapter 1: nat    default: Adapter 2: bridged==> default: Forwarding ports...    default: 80 => 8080 (adapter 1)    default: 22 => 2222 (adapter 1)==> default: Booting VM...==> default: Waiting for machine to boot. This may take a few minutes...The guest machine entered an invalid state while waiting for itto boot. Valid states are 'starting, running'. The machine is in the'poweroff' state. Please verify everything is configuredproperly and try again.If the provider you're using has a GUI that comes with it, it is often helpful to open that and watch the machine, since the GUI often has more helpful error messages than Vagrant can retrieve. For example, if you're using VirtualBox, run `vagrant up` while theVirtualBox GUI is open.

If the preceding error is reported and Virtualbox is run to install the system, the following error occurs: Failed to open a session for the virtual machine, Unable to load R3 module C: \ Program Files \ Oracle \ VirtualBox/VBoxDD. DLL (VBoxDD): getlasterror= 1790 (VERR_UNRESOLVED_ERROR )., you need to use UniversalThemePatcher to restore the uncracked themeservice. dll themeui. dll uxtheme. dll file

Downloaded package-http://pan.baidu.com/s/1c0HGj2g

==> default: Booting VM...==> default: Waiting for machine to boot. This may take a few minutes...    default: SSH address: 127.0.0.1:2222    default: SSH username: vagrant    default: SSH auth method: private key    default: Warning: Connection timeout. Retrying...    default: Warning: Connection timeout. Retrying...    default: Warning: Connection timeout. Retrying...

If default: Warning: Connection timeout. Retrying... is reported, it is recommended to edit Vagrantfile to open the VirtualBox graphical interface vb. gui = true to further analyze the error code and cause.

Export box

Enter the directory E: \ VirtualBox through Shell and execute the command

Vagrant packagevagrant package -- output NAME -- vagrantfile FILE # Optional parameter: -- output NAME: (optional) specify the output file name through NAME -- vagrantfile FILE: (optional) you can directly add Vagrantfile to the box.

The package. box is generated in the current directory. you can maintain consistency at home or by sharing the development environment with team members.

Other commands

Vagrant up (start Virtual Machine)
Vagrant halt (disable virtual machine ?? Shutdown)
Vagrant suspend (pause a virtual machine ?? Only paused. the VM memory and other information will be stored locally as status files. you can resume the operation and continue to use it)
Vagrant resume ?? Corresponds to the previous pause)
Vagrant box remove centos6.6 (remove box, where centos6.6 is the box name)
Vagrant destroy)

Laravel Homestead

For details, refer to the official documentation-http://laravel.com/docs/5.1/homestead

1. download the installation package

vagrant box add laravel/homesteadE:\Homestead>vagrant box add laravel/homestead==> box: Loading metadata for box 'laravel/homestead'    box: URL: https://atlas.hashicorp.com/laravel/homesteadThis box can work with multiple providers! The providers that itcan work with are listed below. Please review the list and choosethe provider you will be working with.1) virtualbox2) vmware_desktopEnter your choice: 1==> box: Adding box 'laravel/homestead' (v0.2.7) for provider: virtualbox    box: Downloading: https://vagrantcloud.com/laravel/boxes/homestead/versions/0.2.7/providers/virtualbox.box    box: Progress: 0% (Rate: 9d/s, Estimated time remaining: 0:05:30)11))

We recommend that you manually import the data after downloading it offline due to network problems in China.

# Enter the command to initialize E: \ Homestead> vagrant init laravelA 'vagrantfile 'has been placed in this directory. You are nowready to 'vagrant up' your first virtual environment! Please readthe comments in the Vagrantfile as well as documentation on 'vagrantup. com 'for more information on using Vagrant. # execute the add command E: \ Homestead> vagrant box add laravel. box => box: Box file was not detected as metadata. adding it directly... ==> box: Adding box 'laravel' (v0) for provider: box: Unpacking necessary files from: file://E:/Homestead/laravel.box Box: Progress: 100% (Rate: 141 M/s, Estimated time remaining: --) ==> box: Successfully added box 'laravel' (v0) for 'virtualbox '! # Check whether the import is successful E: \ Homestead> vagrant box listcentos6.6 (virtualbox, 0) laravel (virtualbox, 0) # start Lavarel HomesteadE: \ Homestead> vagrant upBringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'laravel '... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: Homestead_default_1437217549272_56101 ==> default: Clearing any previously Set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 => 2222 (adapter 1) ==> default: Booting VM... ==> default: Waiting for machine to boot. this may take a few minutes... default: SSH address: 127.0.0.1: 2222 default: SSH username: vagrant default: SSH auth method: private key default: Warni Ng: Connection timeout. retrying... default: Vagrant insecure key detected. vagrant will automatically replace default: this with a newly generated keypair for better security. default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... => default: Machine booted and ready! ==> Default: Checking for guest additions in VM... default: The guest additions on this VM do not match the installed version of default: VirtualBox! In most cases this is fine, but in rare cases it can default: prevent things such as shared folders from working properly. if you see default: shared folder errors, please make sure the guest additions within the default: virtual machine match the version of VirtualBox you have installed on default: your host and reload your VM. default: Guest Additions Version: 4.3.14 default: VirtualBox Version: 5.0 ==> default: Mounting shared folders... default:/vagrant => E:/Homestead

Log on to your account vagrant/vagrant and start your new Laravel Homestead experience.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.