Homestead Laravel Framework development environment installation and configuration in detail under Windows 10 system

Reprinted: https://blog.csdn.net/xiaomayi721025/article/details/84727405

Write at the beginning
about the Laravel framework of Homestead development environment installation and deployment, there are many online articles related technologies, which Eagle Luo an article written very well, my first homestead environment is basically in his article guidance under complete the installation. Original title is: "" Under Windows 7/8/10 system Laravel framework for the development and deployment environment installation Comments (Vagrant + Homestead) ", the original address as follows: https:. //Blog.sbot.io/articles/1
Although Eagle Luo this article has been written in great detail, but I still encountered during the installation process a lot of problems, the most important place to have two: one is the homestead default installation location (default is C: \ Users \ XXX) the problem, and the other is when your windows login user name using Chinese (such as C: \ users \ small ant). homestead virtual machine installation error so, I am here to do their own installation process a comb, but also to the initial installation Laravel Homestead small partner to provide a reference for.

Laravel Homestead About
Laravel Homestead is Laravel official for developers to provide a complete set of heavyweight local development environment, it is a packaged good variety Vagrant box Laravel needed to develop software and tools, the box provides us with an excellent development environment, with it, we no longer need in a local environment installed PHP, Composer, Nginx, MySQL, Memcached, Redis, Node software and other tools, we have no need to worry about messing misuse operating system - because Vagrant box is a one-time, if something goes wrong, can be destroyed in minutes and re-create the Vagrant box!

Laravel Homestead pre-installed software
Laravel Homestead can run on Windows, Mac and Linux and other major operating systems, pre-installed software and tools list as follows:
Ubuntu 18.04
Git
PHP 7.2
PHP 7.1
PHP 7.0
PHP 5.6
Nginx
the Apache (optional)
MySQL
MariaDB (optional)
the SQLite3
of PostgresSQL
Composer
the Node (With the Yarn, Bower, Grunt, and the Gulp)
the Redis
the Memcached
beanstalkd
Mailhog
Neo4j (optional)
MongoDB (optional)
elasticsearch (optional)
ngrok
WP-CLI
the Zend the Z-Ray
Go
Minio

Installing the software and tools needed Laravel Homestead
1, Git
2, VirtualBox
3, Vagrant
4, Homestead Box (Vagrant box Lavavel official offer)

Specific installation and configuration steps Detailed test methods
1, install Git
Windows version of Git official website address: https: //gitforwindows.org/

 

 


Git installation is very simple, it can be by default a.
After the installation is complete, our position in the blank desktop or folder, right-click and choose "Git Bash Here", you can open the Git command window.

 

 

Git initial use of a small partner can right-click and select "options", then the window for text Git and other options set in the git window.

2. Install VirtualBox
VirtualBox is an open source virtual machine software, users can install and execute Solaris, Windows, DOS, Linux, OS / 2 Warp on VirtualBox, BSD and other systems as a client operating system. Laravel Homestead is a virtual machine using VirtualBox created.

VirtualBox's official website address: https: //www.virtualbox.org/

 

 

 

Click the Download button to access the download page, select windows version download, install.

 

 


3, install Vagrant
Vagrant is a virtual machine management tool with which you can quickly build reusable, portable development environment. Laravel Homestead is a good distribution of virtual machine development environment, Laravel official package it into a Vagrant box, user-friendly port it to their own computer.

Vagrant's official website address: https: //www.vagrantup.com/

 

 


Click the Download button to access the download page, select windows version download, install.

 

 


4, install Laravel Homestead
After installing the above three software, we can begin to install the Homestead. There are two installation methods:

The first is an online Installation:
If you feel your speed is fast enough, you can download online in Homestead box (server in a foreign country), you can open Git Bash, enter

vagrant box add laravel / homestead

system will automatically download and install Homestead box for you.

The second is off-line installation :( strongly recommended)
(1), download Laravel Homestead's box boxes
use offline installation, we first go to download the latest version of Laravel Homestead box, its latest version is 6.4.0 .

Download: https: //vagrantcloud.com/laravel/boxes/homestead/versions/6.4.0/providers/virtualbox.box
size of the box is 2.18GB, we recommend the use of Thunder download tools to download.

Note: If you need to download a different version (or the latest version), set above address versions / after the digital version to replace the corresponding version number.

After the download is complete, we'll download the file named Homestead-6.4.0.box. And place a specified directory to store the file, I put it in F: \ virtualBox VMS \ homesteadbox folder.

(2), set VAGRANT_HOME environment variable to change the default location
when Vagrant execute commands will add box Laravel Homestead box related files saved by default in C: \ Users \ xxx.vagrant.d folder (which will have a size of about about 2.2GB of virtual disk files),

 

 

If your C drive space is too small, or you do not want these files in the default user folder, we can change the default location by setting VAGRANT_HOME environment variable setting method may command line window to perform the following two commands in git:

VAGRANT_HOME setX "F.: \ Homestead \ .vagrant.d"
setX VAGRANT_HOME "F.: \ Homestead \ .vagrant.d" / M (system variables)

or add VAGRANT_HOME user variables and system variables directly in the environment variable windwos

 

 


(3), install Laravel Homestead
After setting VAGRANT_HOME environment variable, since we can install the Laravel Homestead.

In Windows, open your store Homestead-6.4.0.box folder (mine is F: \ virtualBox VMS \ homesteadbox), in the file "Git Bash Here" folder window, right-click, select, enter the Git command line window

 

 


Here Run

Box Laravel the Add Vagrant / Homestead Homestead-6.4.0.box
1
After entering the command, we began to import and install the downloaded Homestead box.

 

After waiting a little while, Laravel / Homestead box to add complete.

 

In this case, we specify the directory (F: \ HomeStead) in the more out of a file folder named .vagrant.d, there are some relevant documents Laravel / Homestead box.

Use vagrant box list command in Git can see, Vagrant box list will have a laravel / homestead of box box named.


However, laravel homestead version number / displayed in the list is zero, we want to change it to the correct version (6.4.0) can be opened F: \ HomeStead folder, locate the following path:

F:\HomeStead.vagrant.d\boxes\laravel-VAGRANTSLASH-homestead

The files in a folder named 0 folder renamed Homestead we downloaded the version number, namely 6.4.0.

Then create the folder blank file called metadata_url of (be careful not to have any file name extension, if your system is set up automatically hide extension, please remove the hide, make sure the file without any suffix):

 

Contents of the file in, add the following links:

https://app.vagrantup.com/laravel/boxes/homestead
1
after save, we again use vagrant box list command to see a list box, you will find, laravel / homestead version number has been shown properly.


So far, Laravel Homestead box installed.

5, configure Laravel Homestead
First we go to the official Git laravel Homestead download a configuration folder.
Enter the Git Bash in

clone https://github.com/laravel/homestead.git ~ Git / Homestead
. 1
the command will Github Homestead cloned arranged to project a local ~ / homestead folder (i.e., c: \ users \ xxx directory, xxx is your username). Open the downloaded homestead configuration folder, you will find that there are many homestead project configuration files

 

Copy all the files inside to us before the specified directory F: \ among HomeStead

 

At this point, this folder contains both a vagrant box folder .vagrant.d, also contains Homestead configuration file, that is, and laravel / homestead relevant documents we are placed in this folder, and then we start F can be directly in the virtual machine when Homestead: be \ directory under HomeStead, so as to solve the problem of windows users log in to start the virtual machine error when called Chinese.

Next, we can start creating the Homestead profile:

In F: \ HomeStead directory start Git Bash, execute the command:

bash init.sh
1


Then F: \ HomeStead folder, we can see more of a document called the Homestead.yaml. Use a text editor to open it, you can see something like this:

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
- ~/.ssh/id_rsa

folders:
- map: ~/code
to: /home/vagrant/code

sites:
- map: homestead.test
to: /home/vagrant/code/public

databases:
- homestead

# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp

# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar

# zray:
# If you've already freely registered Z-Ray, you can place the token here.
# - email: [email protected]
# token: foo
# Don't forget to ensure that you have 'zray: "true"' for your site.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
The main implication of these configuration items are:

ip: "192.168.10.10"
1
refers to the IP address of the virtual machine, the initial use of small homestead partners can not modify this address.

Memory: 2048
. 1
refers to the virtual machine configuration memory size, default is 2048MB

cpus: 1
1
refers to the number of configured virtual machine CPU, default is a

Provider: virtualbox
1
indicating which Vagrant provider: virtualbox or vmware_workstation, you can set it to your favorite provider, the default is virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
- ~ / .ssh / id_rsa
. 1
2
. 3
. 4
the authorize ssh behind file is used to enter the public key of the virtual machine, and the latter document is our private keys.

Folders:
- map: ~ / code
to: / Home / Vagrant / code
. 1
2
. 3
Folders for this machine and the virtual machines sync folder, the folder specified map (i.e., ~ / Code) will be mapped to a virtual after system to the specified path, i.e., / home / vagrant / Code.
We Native Code folder synchronization to the virtual machine, so that we can access the virtual machine system to our project file, and changes will be in ~ / Code in the conduct of real-time synchronization corresponds to a virtual machine system file.

sites:
- Map: homestead.test
to: / home / vagrant / code / public
. 1
2
. 3
sites are used to map the address provided Name herein refers to the domain mapping homestead.test / home / vagrant / code / public file folder. In this way, we enter the http in the browser address bar: //homestead.test can access home / home / vagrant / code of the project.

Databases:
- Homestead
1
2
database name here refers to the virtual machine.

Note: The default virtual machine environment MySQL server administrator user name homestead, the password is secret. Recommended use phpmyadmin or HeidiSQL for database management

Suppose we want to create a blog project, project code in F: \ code \ blog, we can make the following configurations:

 

If you want to configure multiple sites, you can refer to the following methods:


To get your domain name set to take effect, but also add domain names pointing to the hosts file:

Homestead.test 192.168.10.10
192.168.10.10 meetup.test
1
2
* path hosts file: C: \ Windows \ System32 \ drivers \ etc *

Note that, host file can not be saved directly modified in this path, we can put it to the desktop, the modification is completed before moving back on the ground. The modified host file contents:

 

6, the establishment of public and private keys for ssh
future, we want to connect homestead virtual machine, then through ssh, the need for public and private keys connected virtual machines, here we come to the establishment of public and private keys.

First of all, we in F: \ HomeStead folder start Git Bash, execute the command mkdir .ssh, create the .ssh folder;

.ssh mkdir
. 1
Next, .ssh Run CD, into the .ssh folder;

.ssh cd
1
Next, we run the command to generate the key:

keygen -t-RSA SSH
. 1
prompted to save secret key file path, input path /f/HomeStead/.ssh/id_rsa, press enter. The next two prompt press enter, the last display keys to create a successful, OK.

 

Open F: \ .ssh file under HomeStead folder, you'll find more than two files, this is the public and private key we just created

 

After creating public and private keys, do not forget to put them in Homestead.yaml file path set.


Next, we can try to start a virtual machine!

7, start the virtual machine Homestead
start Homestead virtual machine, the system creates a virtual machine in virtualbox, the default location to save the virtual machine is C: \ Users \ xxx \ VirtualBox VMs, you can open virtualbox, click the "Administration" -> " global settings "menu to view

 

We call this location to save the virtual machine has changed a bit, I set it to F: \ virtualBox VMS (please change the folder created their own)

 

Set up, let's try to start the virtual machine. (Keep virtualbox to start state, it is said to be a bug windows10)

In F: \ HomeStead folder start as an administrator Git Bash, Git open window, execute the command vagrant up to start the virtual machine.

up Vagrant
1
system started a virtual machine

 

If all goes well, Homestead virtual machines will start successfully.

 

At this point, virtualbox will also appear in a new virtual machine homestead-7

 

Virtual machine files are also stored in the location we specify F: \ virtualBox VMS, rather than stored in the default C: \ Users \ xxx \ VirtualBox VMs directory.

 

Enter the domain name http: //homestead.test/, can access, but because we do not have to create a project, the system displays "No input file specified."

 

Note: Start the virtual machine after homestead, php development environment is already running, the local host without having to start wamp, xampp php and other development environments. I have committed such a low-level error, that the local host would also like to start PHP development environment

8, create a project laravel
enter the code in the windows folder F: \ code, in F: \ Git Bash startup folder code file, open a new window Git, execute the following command to create a folder named code blog of laravel project. (Laravel installation needs the support of the composer, if the composer is not installed on your computer, please first download and install)

composer create-project --prefer-dist laravel/laravel blog
1


Project successfully created appears as shown below.

 

After the project is created, with the vagrant reload command to restart the virtual machine.

reload Vagrant
1
At this point, open the domain name http: //homestead.test/, you can visit the home page of our newly created blog project of the ~ ~

 

9, see the hosts and virtual machines Project Sync circumstances
after the start homestead virtual machine vagrant up command, use the vagrant ssh command to connect virtual machines

vagrant ssh
1


After entering the virtual machine to see what the current directory with the pwd command position, you can see the current location is / home / vagrant, with a view ll command, you will find there is a code folders in the current directory.

 

Enter code folder with the command cd code

code cd
1
with command ll look, you can see there are a blog folder, this is our local host F: \ blog project code which created sync over.

 

10, the database connection problems
after homestead virtual machine starts, we will be able to connect to the mysql database virtual machines, homestead user name, password is secret. Database management tools I use HeidiSQL, after opening HeidiSQL, create a new session, named homestead, enter the above user name, password, and port is 33060, and then click "Open" button.

 

You will find that there are already two of our database configuration in a file Homestead.yaml

 

Open F: \ code \ .env blog project file, database configuration options

 

Description
Homestead default configuration has already done for MySQL and Postgres databases in a virtual machine, it is more convenient, .env these configuration values consistent with Laravel's default configuration provides. Navicat want to connect through a local or Sequel Pro to MySQL or Postgres database on the Homestead, can be achieved by creating a new connection, host IP is 127.0.0.1, for MySQL, the port number is 33060, for Postgres, the port number is 54320, the user name / password homestead / secret. Only from the local connection Homestead database in order to use these non-standard ports, or should use the default port of 3306 and 5432 database connection configuration in Homestead virtual machine.

At this point, the installation and configuration of Homestead development environment on all done!

Several commonly used commands vagrant
Finally, list several common vagrant order to facilitate access to the use of small partners:

$ Vagrant up # start the virtual machine
$ vagrant halt # off the virtual machine
$ vagrant reload # restart the virtual machine
$ vagrant ssh # SSH to the virtual machine
$ exit # exit from the virtual machine
$ vagrant init # initialize
$ vagrant suspend # suspend virtual machines
$ vagrant resume # wake virtual machine
$ vagrant status # View virtual machines running state
$ vagrant destroy # destroy the current virtual machine

#box management command
$ vagrant box list # View the local box lists
$ vagrant box add "box name" box is added to the list of #
$ vagrant box remove "box name" # removed from the list box
---------- ------
Disclaimer: this article is the original article "cloud drifting" CSDN bloggers, follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/xiaomayi721025/article/details/84727405

Guess you like

Origin www.cnblogs.com/yangfei123/p/12446905.html