Detailed explanation of the method of running an Laravel project quickly by using Homestead
- 2021-08-12 02:18:04
- OfStack
Note #
Laravel strives to provide an enjoyable development experience throughout the 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 computer. Don't worry about messing up your operating system! The Vagrant box is completely disposable. If something goes wrong, you can destroy and rebuild the box in a few 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 your amazing Laravel application.
This article describes how to install and run an existing Laravel project. It is compact and provides a summary of only one common operation for quick review.
Installation #
Since our local development environment uses Homestead for rapid deployment, make sure you have successfully installed and configured your local homestead runtime environment before reading this article.
Note: Developers who are not sure how to install and configure the homestead development environment can refer to this article for configuration.
1. Clone code #
git clone {project_path}
2. Configure the local homestead environment #
Run this command line to open the Homestead. yaml file:
homestead edit
Add modifications accordingly:
folders:
- map: /Users/.../demo-name # Your local project address
to: /home/vagrant/demo-name
sites:
- map: demo-name.app
to: /home/vagrant/demo-name/public
databases:
- demo-name # If your project depends on a database , Remember to configure this field . Database name can be customized
Restart homestead:
homestead provision
3. Install dependencies #
Enter the virtual machine:
cd /home/vagrant/demo-name
composer install
4. Generate configuration file #
Replication. env. example is. env
cp .env.example .env
You can modify it according to the file contents of. env, such as database connection, cache settings and so on
5. Create a datasheet and generate test data #
If the project does not depend on the database, you can skip this step
php artisan migrate --seed
6. Modification of hosts #
Run this command line to open the hosts file
sudo vi /etc/hosts
Add 1 line:
127.0.0.1 demo-name.app
After configuration, the browser can directly visit http://demo-name.app.
Summarize