Ibrand Tutorial 0.1:windows + Homestead 5 build Laravel development environment

Source: Internet
Author: User
Tags composer install

Unified development Environment

In order to ensure that the development environment in the study and work to avoid the inconsistency caused by a variety of problems, Laravel official for us to provide a perfect development environment Laravel Homestead, so that we do not have to install the Php,web server or any service software locally.

Homestead can run on any Windows, MAC, or Linux system, including Nginx WEB servers, PHP 7.1, MySQL, Postgressql, Redis, Memcached, Node, and development laravel Use the things you need.

Homestead built-in software:

    • Ubuntu 16.04
    • Git
    • PHP 7.1
    • Nginx
    • Mysql
    • MariaDB
    • Sqlite3
    • Postgres
    • Composer
    • Node (with Yarn, Bower, Grunt, and Gulp)
    • Redis
    • Memcached
    • Beanstalkd
    • Mailhog
    • Ngrok
The
software and knowledge points for beginners may not be well understood, but there is no need to worry about them, which will be used in subsequent tutorials and will be explained in detail in the corresponding chapters.

For this series of tutorials, we will use the current version Homestead 5.1.0 + vagrant 2.0.1 + VirtualBox 5.2.6 + WIN10 to build the development environment.

This set of software environment can also be used normally on Win7.

Related software We have been organized in Baidu Network disk, has the following software:

    1. Git: Version management of the source code.
    2. Tortoisegit: When beginners are unfamiliar with commands, you can use the Visualizer Proxy command to manage the source code.
    3. Sourcetreesetup: graphical git management + git Flow tool
    4. Xshell: Secure terminal management software to log in to the Linux system via SSH.
    5. VirtualBox: Virtual machine Software
    6. Vagrant: Creating a virtualized development environment tool
    7. Homestead-virtualbox5.1.0:homestead the virtual machine file under VirtualBox.
    8. WINSCP:WINSCP is an open-source graphical SFTP client that uses SSH in a Windows environment. The SCP protocol is also supported. Its main function is to copy files securely between local and remote computers.
    9. notepad++: is a relatively good text editor under the Windows operating system, not only has the syntax high brightness display, also has the syntax folding function, and supports the macro as well as expands the basic function the plug-in module.

The above software can be downloaded on Baidu network disk, Link: https://pan.baidu.com/s/1bqVD5MJ Password: 4lku

Recommended installation sequencing: Git->tortoisegit->xshell->sourcetreesetup->virtualbox->vagrant->homestead

In addition to Homestead, other software fool-style next installation can be, some of the use of software in subsequent chapters will also do the relevant introduction.

Important NOTE: Because space is limited, the software involved in the text will not be introduced in detail, the ultimate goal of this article is to ensure that beginners follow the operation, can successfully establish the development environment. Vagrant Some common commands, you can search through Google or Baidu related articles.
Installing Homestead

Need to install git,virtualbox,vagrant three necessary software first.

Add Homestead Box

Create workspace A new folder under C, and copy the downloaded file homestead-virtualbox5.1.0.box Git Bash Here to the directory, and right-click to open the Command window in the current directory.

Add vagrant box add with commands to Homestead box complete

2.0.1  查看 vagrant 版本,表示 vagrant 已经正常安装$ vagrant box add laravel/homestead homestead-virtualbox5.1.0.box

The execution results are as follows:

Configure Homestead

Execute the following command:

$ git clone https://github.com/laravel/homestead.git$ cd homestead$ bash init.sh

The execution results are as follows:

After execution, the file Homestead.yaml is generated and the configuration file is opened with nodepad++, and the role of # +文字的方式进行了说明 The related configuration is passed as follows:

---Ip:"192.168.10.10"Memory2048CPUs1ProviderVirtualBox# virtual machine configuration, including IP address, memory, CPU, and driver type (VirtualBox)Authorize:~/.ssh/id_rsa.pubKeys-~/.ssh/id_rsa# SSH key file, used to directly login to the virtual host, will also use this key, in the back from Github to pull the source code will be usedFolders-Map:~/code  /home/vagrant/code  # file mapping directory, which will automatically synchronize files under Windows system to the virtual machine. ' ~/code ' represents the ' Code ' directory under the current system user directory, as in the example the path of the system is ' C:\Users\32780\code ', ' 32780 ' is the user name of the currently logged on system. sites:-map: homestead.test   to: /home/vagrant/code/public  # site configuration, will automatically generate Laravel Nginx The virtual host file. databases:-homestead# database configuration, not very common in subsequent procedures             

In the end we are in order to hello world achieve a simple, please change to the following configuration:

---Ip:"192.168.10.10"Memory2048CPUs1ProviderVirtualBoxAuthorize:~/.ssh/id_rsa.pubkeys: -  ~/.ssh/id_rsafolders: -map: C:/workspace/code to :  /home/vagrant /codeSites: -map:  homestead.test to :  /home/vagrant/code  Databases: - Homestead              
Generate SSH Key

Before starting the Homestead virtual host we need to generate SSH key and execute the following command:

"[email protected]"  #请替换成你自己的邮箱# Generating public/private rsa key pair...# 三次回车即可生成 ssh key

Start Homestead Virtual Host

You vagrant up need to make a small change before execution to ensure normal startup.

Open C:\Users\32780\.vagrant.d\boxes\laravel-VAGRANTSLASH-homestead directory

Please replace 32780 with the user name you are currently logged into the Windows system

Two changes:

    1. Change the 0 folder to the current Homestead version number 5.1.0
    2. Add the Metadata_url file, the content https://app.vagrantup.com/laravel/boxes/homestead is only added, do not exist any extra space characters.

Next, C:\workspace\homestead execute vagrant up the startup virtual host in the directory.

Hello World Add index.html

hello world Add C:\workspace\code files under the directory, as long as the content is simple. index.html After a successful creation, the files are automatically Homestead synced to the virtual host.

Add hosts

Open C:\Windows\System32\drivers\etc\hosts the file with nodepad++ and add the following code:

192.168.10.10 homestead.test
Just one step.

Browser inputhttp://homestead.test

Hello Laravel

The next step is to deploy the Laravel to the virtual machine, which is a little bit more complicated than the completion of Hello World.

Download source code

Sample source code in the tutorial we put on GitHub, address: https://github.com/ibrandcc/a ...

In c:\workspace the directory right- Git Bash Here Click, Open the Command window, execute the clone following code to source.

git clone https://github.com/ibrandcc/api-tutorial-source.git

An api-tutorial-source extra directory will be created after execution.

Configure Homestead.yaml

New File synchronization Directory

folders: Add the following code below

    map: C:/workspace/api-tutorial-source      to: /mnt/www/api.ibrand.test

Synchronize the source directory mapping to the directory on the /mnt/www/api.ibrand.test virtual host.

Add a virtual Host

sites: Add the following code below

    - map: api.ibrand.test      to: /mnt/www/api.ibrand.test/public
Note that the space
in the file must be a space bar, not the Tab key.

Once added, the Homestead.yaml contents of the file are as follows:

---Ip:"192.168.10.10"Memory2048CPUs1ProviderVirtualBoxAuthorize:~/.ssh/id_rsa.pubKeys-~/.ssh/id_rsaFolders-Map:C:/workspace/codeTo:/home/vagrant/code-Map:C:/workspace/api-tutorial-sourceTo :  /mnt/www/api.ibrand.testsites: -map:  homestead.test to :  /Home /vagrant/code  -map:  api.ibrand.test to :  /mnt/www/api.ibrand.test/public  databases: - Homestead            
Overload Homestead.yaml

After the change, you need vagrant reload --provision to restart the virtual host through the Homestead.yaml command and overload the configuration information.

Configuring Xshell to enter a virtual machine

Xshell software installed prior to startup

Click 新建 to add a new session configuration

    • Name: Homestead
    • Host: 192.168.10.10

Click on the 用户身份验证 left, user name and password are entered:vagrant

Click the OK button to save the settings.

Click the Connect button to make a session connection, the first connection will pop up the following box, select接受并保存

After the operation is completed, the virtual machine will be successfully logged in and the sudo bash command can be root switched to the account after login success.

Installing Laravel
$ cd /mnt/www/api.ibrand.test/$ composer install$ cp .env.example .env$ php artisan key:generate

Add hosts

Open C:\Windows\System32\drivers\etc\hosts the file with nodepad++ and add the following code:

192.168.10.10 api.ibrand.test
One final step

Browser inputhttp://api.ibrand.test

Summarize

The process is a little bit complicated, but setting up this environment avoids many problems in the subsequent redevelopment process, especially if the deployment to the production server after development is complete, there is almost no compatibility problem. This has been proven in the production environment of Ibrand products for each customer, and this is also the official recommended development method of Laravel, so it is worth everyone to master.

For beginners who just get started may not use vagrant, also do not understand the principle, because the length of reason no way to all the details in place, only need to temporarily know the role of the command and meaning, more usage can through their own exploration to learn to master, And the next tutorial will slowly talk about more knowledge points.

Ibrand Tutorial 0.1:windows + Homestead 5 build Laravel 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.