Use vagrant on Windows to build Laravel homestead for a collaborative cross-platform development environment

Source: Internet
Author: User
Tags hhvm install php composer install vps ssl certificate postgres database virtual environment


http://www.itkeyword.com/doc/3863994020922591518 1. Introduction


Laravel is committed to making the entire PHP development process enjoyable, including the local development environment, which officially provides us with a comprehensive set of local development environments--laravel Homestead.



Laravel Homestead is a Vagrant box that packs all the tools and environments needed for Laravel development (Vagrant provides a convenient way to manage and set up virtual machines), which provides us with an excellent development environment, with it, We no longer need to install PHP, HHVM, Web servers, and other tools in our local environment, and we don't have to worry about messing up the operating system at all – because the Vagrant box is a one-time, and if something goes wrong, you can destroy and recreate the Vagrant box in a few minutes!



Homestead can run on Windows, Macs, and Linux Systems, where Nginx, PHP7.0, MySQL, Postgres, Redis, Memcached, node, and many other development Laravel are already installed Apply the things you need.


Note: If you are using Windows, you need to turn on the system's Hardware virtualization (vt-x), which can usually be turned on by the BIOS.

preinstalled Software
    • Ubuntu 14.04
    • Git
    • PHP 7.0
    • HHVM
    • Xdebug
    • Nginx
    • Mysql
    • SQLite 3
    • Postgres
    • Composer
    • Node (with PM2, Bower, Grunt, and Gulp)
    • Redis
    • Memcached
    • Beanstalkd
    • Blackfire Profiler
Environment Preparation
    1. Git
    2. Php
    3. Laravel
    4. Composer
    5. Vagrant
    6. VirtualBox
Install git


1. Download GitHub for Windows



https://windows.github.com/


Install PHP

We recommend that you try to install the latest version of PHP


1. Download PHP



http://windows.php.net/download/



2. Unzip the Directory



My pathD:\php



3. Add Environment variables



System variables--environment variables---Advanced system settings, right-click Computer-->path

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

4. Set up php.ini

Go to the PHP installation directory (for example, D: \ php). Find the php.ini-development file and copy it to the current directory, rename it to php.ini, modify the following configuration
Remove the semicolon in front of extension = php_mbstring.dll (around 888 lines)
Remove the semicolon in front of extension = php_openssl.dll (around line 893)
Remove the semicolon in front of extension_dir = "ext" (around 736 lines)

5. Make environment variables effective

Restart explorer.exe

Install Laravel
1. Download Laravel

http://www.golaravel.com/download/

2. Unzip the directory

My path D: \ laravel-v5.1.4

3. Start Laravel

d:
cd laravel-v5.1.4
D: \ laravel-v5.1.4> php artisan serve
Laravel development server started on http: // localhost: 8000 /
Visit http: // localhost: 8000 / in your browser

artisan's serve command also supports two parameters:

host set host address
port Set the port number on which the web server is listening
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 information
Installing 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 installation process prompts an error that the CA certificate is missing, download cacert.pem to a custom path
http://curl.haxx.se/docs/caextract.html

Then modify the php.ini file (around 1983)

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

3. Test Composer

composer -V
Composer version 1.0-dev (d79427f1a7b15e8f4d46ce8124a4d0c58ba1479c) 2016-01-27 13:01:22
Windows installation can refer to

http://pkg.phpcomposer.com/

2. Installation & setup preparations
VirtualBox virtual machine, basic dependencies
Vagrant is a virtual environment deployment tool based on VirtualBox or vmware, which can package a virtual machine (vbox for short) to others.
Homestead laravel official vbox, integrated environment and a set of special command line tools.
xshell This is a ssh & shell tool for windows. The similar ones include securecrt and putty.
Before using Homestead, you need to install Virtual Box / VMWare and Vagrant, all of which provide an easy-to-use visual installer for common operating systems.

Restart after installation, then open cmd

vagrant --version

Vagrant 1.8.1
 

Download and install the Homestead Vagrant box
By command

After VirtualBox / VMWare and Vagrant are installed, you can add laravel / homesterad to Vagrant by using the following command in a terminal. Downloading the box will take some time, depending on your internet connection speed:

vagrant box add laravel / homestead
If the above command fails, you can use the old version of Vagrant, which requires entering the full URL:

vagrant box add laravel / homestead https://atlas.hashicorp.com/laravel/boxes/homestead
You can download the homestead vbox automatically, but everyone in the domestic network understands it.

It is recommended that students who have vps pass on vps

wget -O homestead.box https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.4.1/providers/virtualbox.box
After downloading manually, download the box to the local computer from vps, or you can try downloading with Thunder. In short, find a way to download this box file and then add it to vagrant with the following command

vagrant box add laravel / homestead file: /// d: /homestead.box
Install Homestead command line tools from GitHub

You can also implement Homestead installation by simply cloning the repository code. Clone the repository into the Homestead directory under the user directory so that the Homestead box can host all other Laravel projects:

cd ~
git clone https://github.com/laravel/homestead.git Homestead
After cloning, run the bash init.sh command in the Homestead directory to create the Homestead.yaml configuration file. The Homestead.yaml configuration file is located in the ~ / .homestead directory:

bash init.sh
Install dependencies
composer install
Execute in Homestead directory

php homestead
Laravel Homestead version 3.0.1
 

Configure Homestead
Setting up the Provider

The provider key in the Homestead.yaml file indicates which Vagrant provider is used: virtualbox, vmware_fushion, or vmware_workstation. You can set it to your favorite provider:

provider: virtualbox
Configure shared folders

Recommendation: Use Vagrant to build an embedded Linux development environment on the Windows platform (2) Tftpd server setup

1. Obtain root privileges Ubuntu uses the user user login by default, and most of the development requires root privileges. Use commands to switch users to the super privileged user root sudo su 2. Download and install

C: \ Users \ stone \ .homestead \ Homestead.yaml

The folders property in the Homestead.yaml file lists all the folders shared by the host and the Homestead virtual machine. Once the files in these directories have been modified, synchronization will be maintained between the local and Homestead virtual machines, if necessary, You can configure multiple shared folders (usually one is sufficient):

folders:
    -map: d: / app
      to: / home / vagrant / Code
If you want to enable NFS, simply add an identity to the sync folder configuration:

folders:
    -map: ~ / Code
      to: / home / vagrant / Code
      type: "nfs"
Configure Nginx site

Not familiar with Nginx? No problem, you can easily map the "domain name" to the specified directory of the Homestead virtual machine through the sites property. An example site is already configured in Homestead.yaml by default. As with shared folders, you can configure multiple sites:

sites:
    -map: homestead.app
      to: / home / vagrant / Code / Laravel / public
You can also make all Homestead sites use HHVM by setting hhvm to true:

sites:
    -map: homestead.app
      to: / home / vagrant / Code / Laravel / public
      hhvm: true
By default, each site is accessible via HTTP (port number: 8000) and HTTPS (port number: 44300).

Modify Hosts File | Visit Website

Don't forget to add the domain name in the Nginx site configuration to the hosts file on your local machine. This file will redirect requests for local domain names to the Homestead virtual machine. On Mac or Linux, the file is located at / etc / hosts. On Windows, it is located at C: \ Windows \ System32 \ drivers \ etc \ hosts and can be added as follows:

The domain name needs to be bound to hosts on this machine: 192.168.10.10 homestead.app
Make sure the IP address is the same as listed in your Homestead.yaml file. Once you place the domain name in the hosts file, you can access the site through the domain name in your browser!

http://homestead.app
Launch Vagrant Box
After configuring the Homestead.yaml file, run the vagrant up command in the Homestead directory, Vagrant will start the virtual machine and automatically configure the shared folder and Nginx site.
To destroy the machine, you can use vagrant destroy -force

vagrant up Box ‘laravel / homestead’ could not be found

Box ‘laravel / homestead’ could not be found

Received the creation of a metadata.json file in the homestead directory, the content is
{
    "name": "laravel / homestead",
    "versions": [{
        "version": "0.4.1",
        "providers": [{
            "name": "virtualbox",
            "url": "file: /// F: /VirtualBox/homestead.box"
        }]
    }]
}

Then run vagrant box add metadata.json

This will install the box with a version and can be confirmed by:

$ vagrant box list
laravel / homestead (virtualbox, 0.4.0)

You will now be able to perform vagrant up using your local box.

Default login and password is just vagrant.

reference:

http: // stackoverflow.com/questions/34946837/box-laravel-homestead-could-not-be-found

GuestAdditions versions on your host (5.0.14) and guest (5.0.6) do not match.

 

This works for me in linux, I think this will solve the problem in windows as well.

 

Quick Solution for Failed to mount folders in Linux guest issue.

 

Add the following line to your Homestead / Vagrantfile:

config.vbguest.auto_update = false
Your d: \ VirtualBox / Homestead / Homestead / Vagrantfile should look like this:

/ ...

Vagrant.configure (VAGRANTFILE_API_VERSION) do | config |

    # To avoid install and uninstall VBoxGuessAdditions during vagrant provisioning.
    config.vbguest.auto_update = false

... /
Save it and execute

$ vagrant destroy --force
$ vagrant up
 

reference:
http://stackoverflow.com/questions/30175290/laravel-homestead-vagrant-vboxsf-not-available-issue

Install Homestead for the specified project
Installing Homestead globally will make each project share the same Homestead box. You can also install Homestead separately for each project. This will create a Vagrantfile under the project, allowing others to execute the vagrant up command in the project, Use Composer to execute the installation command in the project root directory as follows:

composer require laravel / homestead --dev
This installs Homestead in the project. After Homestead is installed, use the make command to generate the Vagrantfile and Homestead.yaml files. The make command will automatically configure the sites and folders properties in Homestead.yaml.

Mac / Linux:

php vendor / bin / homestead make
Windows:

vendor \ bin \ homestead make
Next, run the vagrant up command in a terminal and visit the site at http://homestead.app in your browser. Don't forget to add the domain name homestead.app to the / etc / hosts file.

3. Daily use Global access Homestead
Sometimes you want to run vagrant up anywhere on the file system to start the Homestead virtual machine. To do this, you need to add the Homestead installation directory to the system path. This way you can run homestead or homestead ssh anywhere on your system to start / log in to the virtual machine.

Connect to a virtual machine via SSH
You can SSH to the virtual machine by running vagrant ssh in the Homestead directory

vagrant ssh
But if you need to connect to Homestead in a smoother way, you can add an alias to the host to quickly connect to the Homestead box. After creating the alias, you can use the vm command to SSH to the Homestead virtual machine from anywhere:

alias vm = "ssh [email protected] -p 2222"
Virtual machines can be opened through virtualbox
Username and password: vagrant.

Connect to the database
By default, the MySQL and Postgres databases are configured in the Homestead virtual machine. More conveniently, Laravel's .env is also configured to connect to the Homestead database.

If you want to connect to the MySQL or Postgres database on Homestead through the local Navicat or Sequel Pro, you can do this by creating a new connection. The host IP is 127.0.0.1. For MySQL, the port number is 33060. For Postgres, the port is The number is 54320 and the username / password is homestead / secret.

Note: These non-standard ports can only be used when connecting to Homestead's database locally, and the Homestead virtual machine should still use the default ports 3306 and 5432 for database connection configuration.

Add more sites
While the Homestead virtual machine is running, you may need to add additional Laravel applications to the Nginx site. If you are running multiple Laravel applications in a single Homestead environment, adding a site is as simple as adding the site to the Homestead.yaml file and running the vagrant provision command in the Homestead directory.

The steps to add a domain in Homestead are
Edit the sites and folders projects in the homestead.ymal file
Perform vagrant provision
Configure Cron scheduling tasks
Laravel provides a very convenient way to schedule Cron tasks: you only need to schedule and run the Artisan command schedule: run every minute. schedule: run checks the scheduled tasks defined in the App \ Console \ Kernel class and determines which tasks to run.

If you want to run the schedule: run command for a Homestead site, you need to set schedule to true when you define the site:

sites:
    -map: homestead.app
      to: / home / vagrant / Code / Laravel / public
      schedule: true
The site's Cron tasks are defined in the virtual machine's /etc/cron.d directory.

Port forwarding configuration
By default, Homestead port forwarding is configured as follows:

SSH: 2222 → Forwards To 22
HTTP: 8000 → Forwards To 80
HTTPS: 44300 → Forwards To 443
MySQL: 33060 → Forwards To 3306
Postgres: 54320 → Forwards To 5432
Forward more ports

If you want to add more port forwarding to the Vagrant box, just do the following forwarding protocol settings:

ports:
    -send: 93000
      to: 9300
    -send: 7777
      to: 777
      protocol: udp
4.Performance analysis using Blackfire Profiler
The Blackfire Profiler developed by SensioLabs can automatically collect code execution data, such as memory, CPU time, hard disk I / O, etc. Homestead makes it easy to use this performance analyzer in applications.

The packages required by Blackfire Profiler are pre-installed in the Homestead box. You only need to set the Blackfire Server ID and token in the Homestead.yaml file:

blackfire:
    -id: your-server-id
      token: your-server-token
      client-id: your-client-id
      client-token: your-client-token
After Blackfire credentials are configured, restart Homestead using vagrant provision in the Homestead directory. Before doing so, make sure you have reviewed the Blackfire documentation to learn how to install the appropriate Blackfire extension in your browser.

 

Related passwords

Ubuntu
User name: vagrant
Password: vagrant

mysql password
homestead / secret
root / secret

Virtual machine operation


Without entering the virtual machine, you can also use the following command to manage the virtual machine:

vagrant up (power on the virtual machine)
vagrant halt (shut down the virtual machine-the corresponding is to shut down)
vagrant suspend (suspend the virtual machine-just suspend, the virtual machine memory and other information will be saved locally as a state file, you can continue to use after the resume operation)
vagrant resume (resume virtual machine-corresponding to previous pause)
vagrant destroy (delete the virtual machine, the configuration in the current virtual machine after deletion will not be retained except in the Vagrantfile)

The above commands need to be executed in the Homestead directory
reference:
http://stackoverflow.com/questions/26655516/how-to-install-manually-downloaded-box-for-vagrant
http://stackoverflow.com/questions/34946837/box-laravel-homestead-could-not-be-found
http://stackoverflow.com/questions/25981735/laravel-homestead-stuck-on-vm-login
http://os.51cto.com/art/201507/484834.htm
http://yaojinbu.com/post/2749.html
http://x-bird.qiubs.com/laravel-homestead-intro.html?utm_source=tuicool&utm_medium=referral
http://blog.csdn.net/small_rice_/article/details/45366299
http://blog.csdn.net/markely/article/details/49585887
http://www.ekan001.com/articles/40
http://www.tuicool.com/articles/rIVJRvm

Laravel Homestead with Vagrant on Windows can collaborate with cross-platform development environment

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.