docker 搭建lnmp环境的方法步骤
发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,创建项目目录mkdir php创建如下项目结构sites 目录放置项目文件services 目录放置服务相关配置script 放置自定义脚本├── Readme.md├── docker-compos
千家信息网最后更新 2025年12月03日docker 搭建lnmp环境的方法步骤
创建项目目录
mkdir php
创建如下项目结构
- sites 目录放置项目文件
- services 目录放置服务相关配置
- 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
编辑docker-compose文件
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.11networks: lnmp_net: driver: bridge ipam: config: - subnet: 101.11.11.0/20
编辑services/nginx文件
FROM nginx:1.17.0-alpine# 更新安装源RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories# 设置时区为上海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
编辑services/php文件
FROM php:7.3.6-fpm-alpine3.9# 更新安装源RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories# 设置时区为上海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
以上我们的lnmp环境基本搭建完毕,下面我们针对Php解析做相关的配置
修改services/nginx/nginx.conf,可根据需求自行修改
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;}修改services/nginx/conf.d目录下文件
该目录是各个项目的配置文件,可根据需求配置单个或多个服务
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; #}}启动服务
cd php && docker-compose up --build -d
上述的步骤根据网速的docker的配置执行时间个不相同,因为php中编译了些许扩展,也可根据自身需求做响应的删减
通过浏览器访问http://127.0.0.1:81,如果看到了phpinfo的输出信息,那么恭喜你,你的lnmp环境已经部署完成
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
文件
目录
配置
项目
需求
服务
环境
时区
上海
更新
步骤
相同
信息
内容
单个
多个
就是
时间
浏览器
结构
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
德惠通用网络技术服务诚信合作
组gpu服务器多钱
软件开发和软件测试关系
ping 魔兽服务器
网络安全周宣传标语
区卫健局网络安全应急预案
python大数据库吗
网络安全产品亚洲排名
全国网络安全知识竞赛成绩查询
金蝶软件数据库怎么更换
软件开发什么样的语言最简单
我的世界服务器公告栏mod
服务器安装无线网卡驱动
梦幻诛仙服务器
国家网络安全战略的原则有
嵌入式软件开发价格明细表
匿名网络技术论坛
厦门网络安全中心
谷歌账户提示无法连接服务器
连接更新服务器有问题
如何在网络安全问题中保护自己
web 服务器的管理员
数据库中的外键约束怎么设置
r410服务器打游戏
基本农田数据库建设
网络安全紧急处置演练
安装php的web服务器
计算机软件开发五行属哪个
数据库技术的发展前景前景
把配置文件存到数据库