Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The methods and steps of building lnmp environment by docker

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report