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

How to remove the blue box that appears when the image is used as a hyperlink

I recently used Dreamweaver to make a product pres...

Set the width of the table to be fixed so that it does not change with the text

After setting the table width in the page to width...

How to run multiple MySQL instances in Windows

Preface In Windows, you can start multiple MySQL ...

Summary of methods to prevent users from submitting forms repeatedly

Duplicate form submission is the most common and ...

React entry-level detailed notes

Table of contents 1. Basic understanding of React...

Things to note when writing self-closing XHTML tags

The img tag in XHTML is so-called self-closing, w...

JavaScript implements countdown on front-end web page

Use native JavaScript to simply implement the cou...

How to solve the problem that the project in eclipse cannot be added to tomcat

1. Right-click the project and select properties ...

JavaScript realizes the queue structure process

Table of contents 1. Understanding Queues 2. Enca...

MySQL 5.7 Common Data Types

——Notes from "MySQL in Simple Terms (Second ...

Detailed code for implementing 3D tag cloud in Vue

Preview: Code: Page Sections: <template> &l...

Implementation example of nginx access control

About Nginx, a high-performance, lightweight web ...

Vue implements left and right sliding effect example code

Preface The effect problems used in personal actu...

Use js to call js functions in iframe pages

Recently, I have been working on thesis proposals ...

VMware vCenter 6.7 installation process (graphic tutorial)

background I originally wanted to download a 6.7 ...