How to build lnmp environment in docker

How to build lnmp environment in docker

Create a project directory

mkdir php

Create the following project structure

  • The sites directory is where the project files are placed
  • Services directory places service-related configuration
  • script Place custom script
├── Readme.md
├── docker-compose.yml
├── script
├── services
│ ├── mariadb
│ │ └── Dockerfile
│ ├── nginx
│ │ ├── Dockerfile
│ │ ├── conf.d
│ │ │ └── default.conf
│ │ └── nginx.conf
│ ├── php
│ │ └── Dockerfile
│ └── redis
│ └── Dockerfile
└── sites
 ├── index.html
 └── index.php

 
8 directories, 10 files

Edit the docker-compose file

version: "3"
services: 
 php:
 build: ./services/php
 # ports: 
 # - "9001:9000"
 container_name: lnmp-php
 restart: always
 volumes: 
  - ./sites:/www
 networks:
  lnmp_net:
  ipv4_address: 101.11.11.10

 nginx:
 build: ./services/nginx
 ports:
  - "81:80"
  - "444:443"
 container_name: lnmp-nginx
 restart: always
 volumes: 
  - ./sites:/www
  - ./services/nginx/nginx.conf:/etc/nginx/nginx.conf
  - ./services/nginx/conf.d:/etc/nginx/conf.d:rw
 networks:
  lnmp_net:
  ipv4_address: 101.11.11.11

networks:
 lnmp_net:
 driver: bridge
 ipam:
  config:
  - subnet: 101.11.11.0/20

Edit services/nginx file

FROM nginx:1.17.0-alpine

# Update the installation source RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

# Set the time zone to Shanghai RUN apk update && apk add --upgrade \
 && apk add tzdata \
 && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
 && echo "Asia/Shanghai" > /etc/timezone \
 && apk del tzdata

Edit services/php file

FROM php:7.3.6-fpm-alpine3.9

# Update the installation source RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

# Set the time zone to Shanghai RUN apk update && apk add --no-cache tzdata autoconf gcc g++ make zlib-dev curl-dev\
 && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
 && echo "Asia/Shanghai" > /etc/timezone \
 && apk del tzdata \
 && docker-php-ext-install mysqli pdo_mysql opcache \
 && pecl install grpc protobuf xdebug yaf yar swoole \
 && docker-php-ext-enable xdebug yaf yar swoole grpc protobuf 

Our lnmp environment is basically built above. Now we will configure Php parsing.

Modify services/nginx/nginx.conf, you can modify it according to your needs

user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
 worker_connections 1024;
}


http {
 include /etc/nginx/mime.types;
 default_type application/octet-stream;

 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
      '$status $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for"';

 access_log /var/log/nginx/access.log main;

 sendfile on;
 #tcp_nopush on;

 keepalive_timeout 65;

 #gzip on;

 include /etc/nginx/conf.d/*.conf;
}

Modify the files in the services/nginx/conf.d directory

This directory is the configuration file for each project, which can configure single or multiple services according to needs.

server {
 listen 80;
 server_name localhost;

 #charset koi8-r;
 #access_log /var/log/nginx/host.access.log main;

  #root /usr/share/nginx/html;
 root /www;
 index index.php index.html index.htm;


 #error_page 404 /404.html;

 # redirect server error pages to the static page /50x.html
 #
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
  root /usr/share/nginx/html;
 }

 # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 #
 #location ~ \.php$ {
 # proxy_pass http://127.0.0.1;
 #}

 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 location ~ \.php$ {
 #root html;
  fastcgi_pass 101.11.11.10:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
 }

 # deny access to .htaccess files, if Apache's document root
 # concurs with nginx's one
 #
 #location ~ /\.ht {
 # deny all;
 #}
}

Start the service

cd php && docker-compose up --build -d

The execution time of the above steps varies depending on the network speed and docker configuration. Because some extensions are compiled in PHP, you can also delete them according to your own needs. Visit http://127.0.0.1:81 through the browser. If you see the output information of phpinfo, then congratulations, your lnmp environment has been deployed.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to quickly build an LNMP environment with Docker (latest)
  • Use Docker to create a distributed lnmp image
  • How to deploy LNMP architecture in docker
  • Use Docker to create an integrated service lnmp environment
  • Detailed explanation of using Docker to build LNMP environment
  • Example of compiling LNMP in Docker container

<<:  How to implement an array lazy evaluation library in JavaScript

>>:  A brief discussion on MySQL index optimization analysis

Recommend

Vue2.x - Example of using anti-shake and throttling

Table of contents utils: Use in vue: explain: Ima...

Do you know the weird things in Javascript?

Our veteran predecessors have written countless c...

Tomcat Server Getting Started Super Detailed Tutorial

Table of contents 1. Some concepts of Tomcat –1, ...

Explanation of MySQL performance inspection through show processlist command

The show processlist command is very useful. Some...

ffmpeg Chinese parameter description and usage examples

1. When ffmpeg pushes video files, the encoding f...

A commonplace technique for implementing triangles using CSS (multiple methods)

In some interview experiences, you can often see ...

Summary of bootstrap learning experience-css style design sharing

Due to the needs of the project, I plan to study ...

Implementation of Nginx Intranet Standalone Reverse Proxy

Table of contents 1 Nginx Installation 2 Configur...

Minio lightweight object storage service installation and browser usage tutorial

Table of contents Introduction Install 1. Create ...

How to create a stylish web page design (graphic tutorial)

"Grand" are probably the two words that ...

Troubleshooting and solutions for MySQL auto-increment ID oversize problem

introduction Xiao A was writing code, and DBA Xia...

Understand the initial use of redux in react in one article

Redux is a data state management plug-in. When us...