Get the App
SLTechnology News&Howtos  ›  Servers  › 

The methods and steps of building lnmp environment by docker

Shulou Source: shulou.com Published: 2022-06-02 00:40:24 09月24日 Update

Create a project directory

Mkdir php

Create the following project structure

Sites directory placement project files services directory placement service related configuration script placement custom script ├── Readme.md ├── docker-compose.yml ├── script ├── services │ ├── mariadb │ │ └── Dockerfile │ ├── nginx │ │ ├── Dockerfile │ │ ├── conf.d │ └── default.conf nginx.conf php 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: #-"9001build 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"-"444VO443" 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.11networks: lnmp_net: driver: bridge ipam: config:-subnet: 101.11.11.0 pick 20

Edit the services/nginx file

The FROM nginx:1.17.0-alpine# update installation source RUN sed-I _ apk add _ apk add _ upgrade\ & & apk add tzdata\ & cp / usr/share/zoneinfo/Asia/Shanghai / etc/localtime\ & echo "Asia/Shanghai" > / etc/timezone\ & & apk del tzdata

Edit the services/php file

The FROM php:7.3.6-fpm-alpine3.9# update installation source, RUN sed-I _ etc/apk/repositories#, is set to Shanghai RUN apk update & & apk add-- no-cache tzdata autoconf gcc gears + 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. Let's do some configuration for Php parsing.

Modify services/nginx/nginx.conf, which can be modified 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, and single or multiple services can be configured according to the requirements.

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 500502 503 504 / 50x.hml; location = / 50x.html {root / usr/share/nginx/html } # proxy the PHP scripts to Apache listening on 127.0.0.1 location 80 # location ~. Php$ {# proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1 proxy_pass 9000 # location ~. Php$ {# root html; fastcgi_pass 101.11.11.10 location 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 according to the configuration of the docker of the network speed, because some extensions have been compiled in the php, and you can also delete the response according to your own needs.

Visit http://127.0.0.1:81, through a browser if you see the output of phpinfo, congratulations, your lnmp environment has been deployed

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Tags: File directory configuration project requirements service environment time zone Shanghai update step same information content single multiple that is time browser structure Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Xiaomi NVidia Shulou Tech Info OPPO Reno