Table of Contents
Install docker
Clone laradock
Deploy PHP environment
Laravel configuration file
Nginx configuration
Execute composer
Home Backend Development PHP Tutorial How to use Docker to build a Laravel environment

How to use Docker to build a Laravel environment

Oct 25, 2017 pm 02:26 PM
docker laravel use

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to exit the container by docker How to exit the container by docker Apr 15, 2025 pm 12:15 PM

Four ways to exit Docker container: Use Ctrl D in the container terminal Enter exit command in the container terminal Use docker stop <container_name> Command Use docker kill <container_name> command in the host terminal (force exit)

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to view logs from docker How to view logs from docker Apr 15, 2025 pm 12:24 PM

The methods to view Docker logs include: using the docker logs command, for example: docker logs CONTAINER_NAME Use the docker exec command to run /bin/sh and view the log file, for example: docker exec -it CONTAINER_NAME /bin/sh ; cat /var/log/CONTAINER_NAME.log Use the docker-compose logs command of Docker Compose, for example: docker-compose -f docker-com

Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Apr 18, 2025 am 09:24 AM

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

Laravel user login function Laravel user login function Apr 18, 2025 pm 12:48 PM

Laravel provides a comprehensive Auth framework for implementing user login functions, including: Defining user models (Eloquent model), creating login forms (Blade template engine), writing login controllers (inheriting Auth\LoginController), verifying login requests (Auth::attempt) Redirecting after login is successful (redirect) considering security factors: hash passwords, anti-CSRF protection, rate limiting and security headers. In addition, the Auth framework also provides functions such as resetting passwords, registering and verifying emails. For details, please refer to the Laravel documentation: https://laravel.com/doc

See all articles