Build a virtual machine environment through Vagrant

Source: Internet
Author: User
Tags hhvm ssh access vmware fusion

Build a virtual machine environment through Vagrant
Introduction

Laravel is committed to making PHP development experience more enjoyable and also includes your local development environment. Vagrant provides a simple and elegant way to manage and supply virtual machines.

Laravel Homestead is an officially pre-loaded Vagrant "package" that provides you with a beautiful development environment, you do not need to install PHP, HHVM, web server, or any server software on your local computer. Don't worry about messing up your system! The Vagrant package can handle everything. If something goes wrong, you can quickly destroy and recreate the virtual machine within a few minutes.

Homestead can run on any Windows, Mac, or Linux, it contains Nginx Web servers, PHP 5.6, MySQL, ipvs, Redis, Memcached, and all the software you need to develop brilliant Laravel applications.

Note: If you are a Windows user, you may need to enable hardware Virtualization (VT-x ). You usually need to enable it through BIOS.

Homestead is currently built and tested in Vagrant 1.7.

Built-in software
  • Ubuntu 14.04
  • Python 5.6
  • HHVM
  • Nginx
  • MySQL
  • Postgres
  • Node (With Bower, Grunt, and Gulp)
  • Redis
  • Memcached
  • Beanstalkd
  • Laravel Envoy
  • Blackfire Profiler
Install and configure VirtualBox/VMWare and Vagrant

Before starting your Homestead environment, you must first install VirtualBox and Vagrant. Both sets of software provide easy-to-use visual installation programs on each platform.

VMware

In addition to VirtualBox, Homestead also supports VMware. If you use VMware as the provider, You need to purchase VMware Fusion/Desktop and VMware Vagrant plug-in. VMware to provide faster shared folders with better performance.

Added Vagrant package

After VirtualBox/VMware and Vagrant are installed, run the following command on the terminal to install the 'laravel/homestead 'package into your Vagrant installer. It takes you a little time to download the package. The duration is determined by your network speed:

vagrant box add laravel/homestead

If this command fails, you may install an old version of Vagrant and you need to specify a complete URL:

vagrant box add laravel/homestead https://atlas.hashicorp.com/laravel/boxes/homestead
Install Homestead

You can install Homestead by manually copying the resource library. Copy the resource library to your "home" DirectoryHomesteadAs a result, the Homestead package will provide host services to all your Laravel (and PHP) applications:

git clone https://github.com/laravel/homestead.git Homestead

Once you have cloned the Homestead repository, runbash init.shCommand to createHomestead.yamlConfiguration file:

bash init.sh

ThisHomestead.yamlFiles will be placed in your~/.homesteadDirectory.

Configure your Provider

InHomestead.yamlFileproviderKey indicates the Vagrant prodiver to be used:virtualbox,vmware_fusion(Mac OS X), orvmware_workstation(Windows), you can set provider according to your preferences.

provider: virtualbox
Configure your SSH key

Then you need to editHomestead.yaml. You can configure your SSH Public Key in the file and the shared directory between the main machine and the Homestead virtual machine.

If you do not have an SSH key, you can use the following commands to create an SSH key group on Mac and Linux:

ssh-keygen -t rsa -C "you@homestead"

In Windows, you need to install Git and useGit BashTo execute the preceding command. You can also use PuTTY and PuTTYgen.

Once you create an SSH key, rememberHomestead.yamlFileauthorizeAttribute specifies the Key Path.

Configure your shared folder

Homestead.yamlFilefoldersAttribute lists all the folders you want to share in the Homestead environment. If the files in these folders change, they will be synchronized to your local machine and Homestead environment. You can configure all the shared folders you need.

To enable NFS, you only needfoldersAdd an identifier:

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

Not familiar with Nginx? It doesn't matter.sitesAttribute allows you to easily correspond toDomain NameTo a directory in the homestead environment. The site in one example is configured inHomestead.yamlFile. Similarly, you can add any site you need to your Homestead environment. Homestead provides a convenient virtualization environment for each Laravel application in progress.

You can configurehhvmThe property istrueTo make the virtual site support HHVM:

sites:    - map: homestead.app      to: /home/vagrant/Code/Laravel/public      hhvm: true

Each site will be accessible by HTTP via port 8000 and HTTPS via port 44300.

Bash Aliases

To add Bash aliases to your Homestead package, add the content~/.homesteadDirectoryaliasesFile.

Start the Vagrant package

When you finish editing according to your preferencesHomestead.yamlEnter your Homestead folder in the terminal and executevagrant upCommand.

Vagrant will start the VM and automatically configure your shared directory and Nginx site. To remove a virtual machine, you can usevagrant destroy --forceCommand.

For your Nginx site, do not forgethostsAdd the "Domain Name" to the file.hostsFile will direct your local domain name site requests to your Homestead environment. In Mac and Linux, this file is stored in/etc/hosts. In Windows, it is placed inC:\Windows\System32\drivers\etc\hosts. The content you want to add is similar to the following:

192.168.10.10  homestead.app

Make sure that the IP address matches yourHomestead.yamlFile. Once you add a domain name to yourhostsFile, you can access your site through a web browser.

http://homestead.app

Continue reading, and you will learn how to connect to the database!

Common usage: connect through SSH

To connect to your Homestead environment through SSH, enter your Homestead directory in the terminal and executevagrant sshCommand.

Because you may often need to access your Homestead virtual machine through SSH, you can consider creating an "alias" on your main machine for fast SSH access to the Homestead Virtual Machine:

alias vm="ssh vagrant@127.0.0.1 -p 2222"

Once you create this alias, you can simply use the "vm" command to access your Homestead vm through SSH no matter which directory you are on the main machine.

You can also usevagrant sshCommand.

Connect to database

InHomesteadIn the package, the MySQL and ipvs databases are pre-configured. For ease, Laravel'slocalThe database configuration has been completed by default.

If you want to connect to MySQL or ipvs database through Navicat or Sequel Pro on the local machine, you can connect127.0.0.1Port 33060 (MySQL) or 54320 (S ). The account and password arehomestead/secret.

Note: from the local end, you should only use these non-standard connection ports to connect to the database. When Laravel runs on a VM, the default port 3306 and port 5432 are configured in the Laravel database configuration file.

Add more sites

After the installation and running in the Homestead environment, you may need to add more Nginx sites for the Laravel application. You can run a lot of Laravel installation programs in a single Homestead environment. There are two ways to achieve this: first, inHomestead.yamlAdd a site to the file and execute it in the Homestead directory.vagrant provision.

Note: This operation is destructive.provisionCommand, your existing database will be destroyed and re-created.

You can also useserveCommand file. To useserveCommand file. first enter the Homestead environment through SSH and execute the following command:

serve domain.app /home/vagrant/Code/path/to/public/directory 80

Note: During executionserveAfter the command, do not forget to add the new site to the Local MachinehostsFile.

Connection Port

The following ports will be forwarded to the Homestead environment:

  • 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
Add additional port

You can also customize the forwarding to Vagrant box by specifying the Protocol:

ports:    - send: 93000      to: 9300    - send: 7777      to: 777      protocol: udp

Blackfire Profiler

Blackfire Profiler is an analysis tool created by SensioLabs. It automatically collects data during code execution, such as RAM, CPU time, and disk I/O. if you use Homestead, it is very easy to use this analysis tool.

The package required by blackfire has been installed in Homestead box.Homestead.yamlSet the Server ID and token in the file:

blackfire:    - id: your-server-id      token: your-server-token      client-id: your-client-id      client-token: your-client-token

When you have set the Blackfire credential information, usevagrant provisionMake the configuration take effect. Of course, you also need to read the Blackfire documentation to learn how to install the Blackfire extension in your browser.

How to Use vagrant to install a Hadoop cluster on a virtual machine

Efficient Puppet module Management in Vagrant

Use Vagrant and Fabric for Integration Testing

Build a development environment using Vagrant

Configure the Vagrant environment in Windows

Build a development environment using Vagrant

This article permanently updates the link address:

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.