Construction of Laravel Local Environment: Deployment of Homestead Development Environment

01-28-2024

Laravel framework is constantly optimized in the php development process, and of course it also includes the development of local environment. Let's take a concrete look at the deployment content of Homestead development environment in Laravel framework. First of all, the following concepts are white

VirtualBox-the virtual machine software of Oracle company, which can run on most popular systems at present;

Vagrant provides a command line interface that allows automatic installation of virtual machines, and because it is a provision text file written by script, it is possible to share virtual machine configuration. Homestead is built on Vagrant.

Laravel Homestead is an official pre-packaged Vagrant Box, which is a prototype of a virtual machine. It is used to quickly produce a fully configured server virtual machine running on VirtualBox.

The virtual machine produced by Homestead provides a complete development environment. With this environment, you don't have to worry that all kinds of software settings will mess up your operating system.

Because it is a virtual machine, when it fails, it can be destroyed and rebuilt in a few minutes.

Homestead can run on all Windows, Mac and Linux, and it includes Nginx, PHP 5.5, MySQL, Postgres, Redis, Memcached and all other software you need to develop Laravel applications.

Homestead can be used to unify the development environment when many people are working together, so that programmers can concentrate more on the business logic of the program and avoid all kinds of confusion caused by different development environments.

The agreement assumes that we are going to develop a project, and the name of the project is mytwitter.

First, create the project root folder mytwitter_project in the code folder where we store the code, and then all our operations will be carried out under this project.

cd ~/codemkdir mytwitter_project cd mytwitter_project

Install virtualbox and vagrant Download and install VirtualBox and Vagrant here.

Just download and install the GUI installation package directly.

Downloading and configuring HomesteadHomestead includes the following two things.

A vagrant box virtual machine, in which everything is downloaded;

Github code base, which is loaded with vagrant configuration scripts, is used to automatically configure the network, port mapping, and other configurations used in development.

Clone homestead project Clone homestead project to local under folder.

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

Join homestead box Execute the following command to add a box.

vagrant box add laravel/homestead

Online downloading will be very slow, and it is usually fast.

You can download the latest box file.

Https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.5.0//new version address.

Execute the following command after downloading, and change /path/to/virtualbox.box to the correct path.

vagrant box add laravel/homestead /path/to/virtualbox.box

Execute the following command in windows.

vagrant box add laravel/homestead file:///D:/download/virtubox.box

Modify the configuration of homestead. Modify the file Homestead.yaml in Homestead project according to your situation, similar to the following.

---ip: "192.168.10.10"memory: 2048cpus: 1authorize: /Users/me/.ssh/id_rsa.pub keys: - /Users/me/.ssh/id_rsa folders: - map: /Users/me/code/mytwitter_project/mytwitter to: /home/vagrant/mytwitter sites: - map: mytwitter.app to: /home/vagrant/mytwitter/public variables: - key: APP_ENV value: local

Configure the hosts file to modify the hosts file of this machine, allowing access through a custom domain name, which is set in Homestead.yaml above.

sudo vi /etc/hosts

Add the following line

127.0.0.1 mytwitter.app

Initialize homestead virtual machine cd Homestead vagrant up Note: To delete the Vagrantfile file in the homestead directory and regenerate it, use the command: vagrant init generation. And then at startup vagrant u

See the prompt message after starting.

Finally, whether the connection can be successful is tested. The files in the ~/mytwitter folder in the virtual machine are consistent with the local files.

vagrant ssh cd ~/mytwitter ll

The browser visited http://mytwitter.app:8000/.

At this point, the installation was successful.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us