Install VirtualBox

  • A virtual machine software
  • Provides a virtual environment for running VMS

Install the Vagrant

  • A software to create virtual machines
  • Use it to create a Homestead virtual machine

Add packages with Vagrant (Homestead Box)

  • vagrant box add laravel/homestead
  • A Laravel/Homestead virtual machine box was created
  • An integrated (Nginx, PHP, MySQL, Postgres, Redis, Memcached) of the virtual machine

Installing and using Homestead (admin script)

  • git clone https://github.com/laravel/homestead.git Homestead
  • A script written in Ruby and Shell
  • from~/Homestead/Homestead.yamlAfter reading the configuration information and translating it into the Vagrant command during the provision, you can configure VMS

Initialize the configuration file

  • createHomestead.yamlThe configuration file
    • linux: bash init.sh
    • windows: ./init.sh

Configuration favored. Yaml

  • Vm Settings
    • ip
    • memory
    • cpus
    • provider
  • SSH key login configuration
    • authorize
    • Keys (Array option, fill in the local SSH private key file address)
  • Shared Folder Configuration
    • Folders (Map folders on the local machine to virtual machine)
      • Map (corresponding to local folder)
      • To (corresponding to the folder on Homestead)
  • Site configuration
    • Sites (Use domain names to access applications in VMS on the local host)
      • Map (corresponding site domain name)
      • To (corresponding to the folder on Homestead)
  • Database Configuration
    • Databases (specify database name)
  • Custom variable
    • variables
      • key
      • value

Run the Vagrant

  • Go to the Homestead (Administrative Scripts) directory
    • cd ~/Homestead
  • Start the vagrant
    • vagrant up
  • Log in to the Homestead VM over SSH

Install Laravel

  • Create a Laravel project using Composer based on the Settings of Sites in Homestead.yaml
    • Composer create-project laravel-laravel laravel --prefer-dist "5.5.\*"

Access the Laravel site from the host

  • Use the domain name specified in Homestead Sites. map on the host to access sites on the VM

Summary of installation process:

  1. Add Homestead Box to VirtualBox via Vagrant
  2. Use the Homestead management script to generate a configuration file
  3. By setting folders and Sites in the configuration file, the purpose of communication between the host and virtual machine is achieved
  4. Vagrant’s behavior is influenced by Homestead administration scripts to configure the virtual machine

Summary of virtual environment startup process

  1. Run Vagrant from the Homestead Administration Scripts directory
  2. The Homestead administration script reads the data in Homestead.yaml and parses it into the Vagrant command
  3. Vagrant started the virtual machine according to the configuration of the Homestead administration script

Summary of development process

  1. Start Vagrant in the Homestead Admin scripts directory
  2. At this point, in homestead. yaml, the host folder set in folders. Map has been shared with the VIRTUAL machine folder set in folders
  3. You can use the domain name specified in Sites. map in Homestead.yaml to access the site content on the VM

Summary of Access Process

  1. Visit www.test.com in your browser
  2. Based on the host file, the browser resolves the domain name to the specified VM address and accesses the IP address
  3. Port 80 of the VIRTUAL machine listens to access and returns the site content to the host browser
  4. The browser on the host displays the web site content

Reference article:

Laravel Tutorial – Getting started with Web development