IBrand tutorial 0.1: Build a Laravel development environment in Windows + Homestead 5, ibrandlaravel
Unified Development Environment
To avoid various problems caused by inconsistent development environments during learning and work, Laravel officially provides us with a perfect development environment Laravel Homestead, this eliminates the need to install PHP, web servers, or any service software locally.
Homestead can run on any Windows, Mac, or Linux system, including Nginx Web server, PHP 7.1, MySQL, PostgresSQL, Redis, Memcached, Node, and what is needed to develop laravel applications.
Homestead built-in software:
- Ubuntu 16.04
- Git
- Python 7.1
- Nginx
- MySQL
- MariaDB
- Sqlite3
- Postgres
- Composer
- Node (with Yarn, Bower, Grunt, and Gulp)
- Redis
- Memcached
- Beanstalkd
- Mailhog
- Ngrok
I may not know much about the software and knowledge related to beginners, but I don't need to worry about it. It will be used in subsequent tutorials and relevant chapters will be explained in detail.
In this series of tutorials, we will use the latest version Homestead 5.1.0 + vagrant 2.0.1 + VirtualBox 5.2.6 + Win10 to build the development environment.
This software environment can also be used normally in Win7.
We have already sorted out the related software on the Baidu network disk, which includes the following software:
The above software can be downloaded on the Baidu network disk, link: https://pan.baidu.com/s/1bqVD5MJ password: 4lku
Recommended installation sequence: Git-> TortoiseGit-> Xshell-> SourceTreeSetup-> VirtualBox-> Vagrant-> Homestead
In addition to Homestead, other software can be installed in the next step. The usage of some software will be introduced in the subsequent sections.
Important: due to limited space, the software involved in this article will not be described in detail for the time being. The ultimate goal of this article is to ensure that beginners can successfully establish a development environment after performing their operations. Common Vagrant commands can be searched for related articles by Google or Baidu.
Install Homestead
Install three necessary software: Git, VirtualBox, and Vagrant.
Add Homestead Box
Create under drive Cworkspace
Folder, and the downloadedhomestead-virtualbox5.1.0.box
Copy the file to this directory and right-click and selectGit Bash Here
Open the command window in the current directory.
Passvagrant box add
Command to completeHomestead box
Add
$ Vagrant -- version # Vagrant 2.0.1 view vagrant version, indicating that vagrant has been properly installed $ vagrant box add laravel/homestead homestead-virtualbox5.1.0.box
Shows the execution result:
Configure Homestead
Run the following command:
$ git clone https://github.com/laravel/homestead.git$ cd homestead$ bash init.sh
Shows the execution result:
Generated after executionHomestead.yaml
File, use Nodepad ++ to open the configuration file.# + Description of Text
, As shown below:
--- Ip: "192.168.10.10" memory: 2048 cpus: 1 provider: virtualbox # virtual machine configuration, including ip address, memory, cpu, and driver type (virtualbox) authorize :~ /. Ssh/id_rsa.pubkeys :-~ /. Ssh/id_rsa # ssh key file, which is used to directly log on to the VM. This key will also be used later. folders:-map: ~ will be used when pulling the source code from Github :~ /Code to:/home/vagrant/code # file ing directory. This configuration automatically synchronizes files in Windows to virtual machines. '~ /Code' indicates the 'code' directory under the current system user directory. In this example, the system path is 'c: \ Users \ 32780 \ Code ', '200' is the name of the user currently logged on to the system. Sites:-map: homestead. test to:/home/vagrant/code/public # site configuration, the nginx VM file of Laravel is automatically generated. Databases:-homestead # database configuration, which is not frequently used in subsequent processes
In the end, we want to implement a simplehello world
, Change to the following Configuration:
---ip: "192.168.10.10"memory: 2048cpus: 1provider: virtualboxauthorize: ~/.ssh/id_rsa.pubkeys: - ~/.ssh/id_rsafolders: - map: C:/workspace/code to: /home/vagrant/codesites: - map: homestead.test to: /home/vagrant/codedatabases: - homestead
Generate an SSH key
Before starting the Homestead Vm, We need to generate an SSH key and execute the following command:
$ Ssh-keygen-t rsa-C "xxxxx@xxxxx.com" # Replace it with your own mailbox # Generating public/private rsa key pair... # Press enter three times to generate an ssh key
Start the Homestead VM
Runvagrant up
You need to make minor changes to ensure normal startup.
OpenC:\Users\32780\.vagrant.d\boxes\laravel-VAGRANTSLASH-homestead
Directory
Replace 32780 with your current user name for logging on to windows.
Two changes:
NextC:\workspace\homestead
Directoryvagrant up
Start the VM.
Add index.html to Hello World
InC:\workspace\code
Addindex.html
File, the content only requires a simplehello world
You can. After the file is created, it is automatically synchronizedHomestead
On the VM.
Add hosts
Open with Nodepad ++C:\Windows\System32\drivers\etc\hosts
File, add the following code:
192.168.10.10 homestead.test
Only one step away
Browser Inputhttp://homestead.test
Hello Laravel
Next, deploy Laravel to a VM, which is a little more complicated than hello world.
Download source code
Sample source code in the Tutorial we put on github, address: https://github.com/ibrandcc/a...
Inc:\workspace
Right-click the DirectoryGit Bash Here
Open the command window and run the following code:clone
Source code.
git clone https://github.com/ibrandcc/api-tutorial-source.git
After the execution is completed, one moreapi-tutorial-source
Directory.
Configure Homestead. yaml
Add a file synchronization directory
Infolders:
Add the following code
- map: C:/workspace/api-tutorial-source to: /mnt/www/api.ibrand.test
Synchronize the source code directory ing TO/mnt/www/api.ibrand.test
Directory.
Add VM
Insites:
Add the following code
- map: api.ibrand.test to: /mnt/www/api.ibrand.test/public
Note that the blank space in the file must be a space specified by the Space key. You cannot use the Tab key.
After adding,Homestead.yaml
The file content is as follows:
---ip: "192.168.10.10"memory: 2048cpus: 1provider: virtualboxauthorize: ~/.ssh/id_rsa.pubkeys: - ~/.ssh/id_rsafolders: - map: C:/workspace/code to: /home/vagrant/code - map: C:/workspace/api-tutorial-source to: /mnt/www/api.ibrand.testsites: - map: homestead.test to: /home/vagrant/code - map: api.ibrand.test to: /mnt/www/api.ibrand.test/publicdatabases: - homestead
Heavy Load
Homestead.yaml
After the changevagrant reload --provision
Command to restart the VM and reloadHomestead.yaml
Configuration Information in.
Configure Xshell to enter the VM
Start the previously installed Xshell Software
ClickNew
, Add new session configuration
- Name: homestead
- HOST: 192.168.10.10
ClickUser Authentication
, Enter both the user name and password:vagrant
Click OK to save the settings.
Click the connection button to connect to the session. The following prompt box is displayed for the first connection. SelectAccept and save
After the operation is completed, the VM will be successfully logged on.sudo bash
Command switchroot
Account
Install Laravel
$ cd /mnt/www/api.ibrand.test/$ composer install$ cp .env.example .env$ php artisan key:generate
Add hosts
Open with Nodepad ++C:\Windows\System32\drivers\etc\hosts
File, add the following code:
192.168.10.10 api.ibrand.test
Last step
Browser Inputhttp://api.ibrand.test
Summary
The process is a little complicated, but setting up this environment can avoid many problems in the subsequent development process, especially deployment to the production server after the development is complete, and there is almost no compatibility problem. This has been verified in the production environment of iBrand products, and it is also the development method officially recommended by Laravel, so it is worth your understanding.
For beginners, vagrant may not be used or understand the principles. Due to space reasons, it is impossible to describe all the details in place. You only need to know the role and significance of the commands that appear for the moment, more usage can be learned through your own exploration, and more knowledge points will be introduced in subsequent tutorials.