Home  >  Article  >  Backend Development  >  Detailed explanation of how to use Homestead to quickly run Laravel projects

Detailed explanation of how to use Homestead to quickly run Laravel projects

*文
*文Original
2018-01-05 09:22:011849browse

How to use Homestead to quickly run Laravel projects? This article mainly introduces you to the relevant information on how to quickly run a Laravel project using Homestead. The article introduces it in detail through the example code, which has certain reference learning value for everyone's study or work. Friends who need it follow the editor below. Come and learn together. I hope to be helpful.

Description

#Laravel strives to provide a pleasant development experience for the entire PHP development process, including the developer's local development environment.

Laravel Homestead is an official, pre-packaged Vagrant "box" that provides you with a fantastic development environment without requiring you to install PHP, HHVM, web servers and other server software on your machine. . No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and rebuild the chest in minutes!

Homestead runs on any Windows, Mac or Linux system and includes Nginx, PHP 5.6, MySQL, Postgres, Redis, Memcached and all the other software you need to develop amazing Laravel applications.

This article will introduce how to install and run an existing Laravel project. The text is compact and only summarizes some common operations for quick review.

Installation

#Since our local development environment uses Homestead for rapid deployment, before reading this article, you need to make sure your local The homestead operating environment has been successfully installed and configured.

Note: Developers who do not know how to install and configure the homestead development environment can refer to this article for configuration.

1. Clone the code

#
git clone {project_path}

2. Configure the local homestead environment

# Run this command line to open the Homestead.yaml file:

homestead edit

Correspondingly add modifications:

folders:
 - map: /Users/.../demo-name # 你的本地项目地址
 to: /home/vagrant/demo-name

sites:
 - map: demo-name.app
 to: /home/vagrant/demo-name/public

databases:
 - demo-name # 如果项目依赖数据库,请记得配置此字段.数据库名称可自定义

Restart homestead:

homestead provision

3. Install dependencies

#Enter the virtual machine:

cd /home/vagrant/demo-name
composer install

4. Generate configuration file

#Copy .env.example to .env

cp .env.example .env

You can make corresponding modifications according to the content of the .env file, such as database connection, cache settings, etc.

5. Create a data table and generate test data

#If the project does not depend on the database, you can skip this step

php artisan migrate --seed

6 . Modify hosts

#Run this command line to open the hosts file

sudo vi /etc/hosts

Add a new line:

127.0.0.1 demo-name.app

After configuration, the browser directly accesses http: //demo-name.app.

Related recommendations:

Detailed explanation of how Laravel uses database transactions and exception handling

Detailed explanation of how to obtain routing parameters in Laravel

Detailed explanation of the loading process and principle of Facade in Laravel

The above is the detailed content of Detailed explanation of how to use Homestead to quickly run Laravel projects. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn