Home > Backend Development > PHP Tutorial > How to use Docker to build a Laravel environment

How to use Docker to build a Laravel environment

一个新手
Release: 2023-03-16 19:00:01
Original
2523 people have browsed it

Laravel officially provides Homestead and Valet as local development environments. Homestead is an official pre-packaged Vagrant Box, which is a virtual machine. However, compared with docker, it takes up too much space, starts slowly, and responds very slowly. , now with docker, a better way, you can easily and conveniently build a complete PHP development environment.

This article introduces how to use docker to build a Laravel local environment.

Install docker

First install docker.

Clone laradock

laradock official documentation: http://laradock.io/

laradock github: https://github.com/laradock/l...

laradock is a fully functional PHP running environment for docker, deployed using docker-compose. (Special note: It is not only used to build the Laravel environment, but also supports all other PHP frameworks. It is a complete set of PHP environments.)

Deploy PHP environment

1. Clone laradock

git clone https://github.com/Laradock/laradock.git
Copy after login

2. Create an environment variable file

cp env-example .env
Copy after login

3. Directly use docker-compose to run the services that need to be enabled, such as:

docker-compose up -d nginx mysql redis beanstalkd
Copy after login

This will start the required PHP running environment, php-fpm will run by default, so there is no need to specify it.

How to use Docker to build a Laravel environment

Laravel configuration file

Laravel configuration file needs to pay attention to the address of mysql and redis in the .env file It needs to be filled in like this instead of the ip address form:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=tanteng.me
DB_USERNAME=root
DB_PASSWORD=root
 
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
Copy after login

Nginx configuration

To access the site locally through the domain name, you need to bind the domain name in the host to the local one, and you also need to add nginx configuration. .

How to use Docker to build a Laravel environment

As shown in the figure, add the configuration file in the sites directory under the nginx folder of the laradock project.

Execute composer

To perform composer and other operations, you need to enter the workspace container. Use the command:

docker-compose exec workspace bash
Copy after login

Enter the workspace container, and you can perform compose commands and other operations. .

For specific usage issues, please refer to laradock official documentation, which is explained above.


The above is the detailed content of How to use Docker to build a Laravel environment. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template