docker 搭建php 开发环境 添加扩展redis、swoole、xdebug(1)

docker-compose搭建lnmp

先决条件

首先需要安装docker

安装docker-compost

1、创建lnmp工作目录

bash 复制代码
#创建三个目录
mkdir lnmp && cd lnmp
mkdir -p nginx/conf php mysql/data lnmp/www


#编写nginx 配置文件  nginx/conf/default.conf
vim nginx/conf/default.conf

server {
    listen       80;
    root   /usr/share/nginx/html;
    index   index.html index.htm index.php;


    # 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;
    }

    location / {
        index  index.html index.htm index.php ;
        try_files $uri $uri/ /index.php?$query_string;
        autoindex  on;
    }


    location ~ \.php$ {
        #php73是容器命名
        fastcgi_pass   php:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
    }

}

2、编写php镜像文件Dockerfile

因为php需要安装一些扩展文件 使用dockerfile进行镜像构建

bash 复制代码
vim php/Dockerfile

# 基础
FROM php:7.2-fpm

# 修改时区
ENV TZ Asia/Shanghai
RUN date -R

# 换源
RUN echo 'deb http://mirrors.ustc.edu.cn/debian stable main contrib non-free' >/etc/apt/sources.list
RUN echo 'deb http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free' >>/etc/apt/sources.list
RUN apt-get update --fix-missing && apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev  \
        && docker-php-ext-configure gd --with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include/jpeg \
        && docker-php-ext-install gd mysqli opcache pdo_mysql gd zip

ENV PHPREDIS_VERSION 5.0.1
ENV PHPXDEBUG_VERSION 2.6.0
ENV PHPSWOOLE_VERSION 4.5.10

RUN pecl install redis-$PHPREDIS_VERSION \
    && pecl install xdebug-$PHPXDEBUG_VERSION \
    && pecl install swoole-$PHPSWOOLE_VERSION \
    && docker-php-ext-enable redis xdebug swoole

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
     && php composer-setup.php \
     && php -r "unlink('composer-setup.php');" \
     && mv composer.phar /usr/local/bin/composer \
     && composer config -g repo.packagist composer https://packagist.phpcomposer.com
RUN apt-get install -y git

RUN rm -rf /var/cache/apt/* \
    && rm -rf /var/lib/apt/lists/*
RUN mkdir /var/lib/sessions \
    && chmod o=rwx -R /var/lib/sessions
#容器启动时执行指令
CMD ["php-fpm"]
相关推荐
闪电悠米6 小时前
黑马点评-Redis 消息队列-03_stream_consumer_group
开发语言·数据库·redis·分布式·缓存·junit·lua
8125035336 小时前
第 9 篇:子网掩码:如何划分“小区”
开发语言·php
我叫黑大帅7 小时前
通过php 中的Route:: 的写法了解什么是静态类调用
后端·面试·php
正经教主7 小时前
【docker基础】第五课:Docker网络详解
运维·docker·容器
鹤鸣的日常8 小时前
前端运行时动态环境变量方案
前端·react.js·docker·前端框架·vue·gitlab
佛祖让我来巡山9 小时前
线上 Redis 突然“爆”了,怎么办?
redis·redis宕机·redis崩了·redis线上事故
三十..10 小时前
Redis 核心原理与高可用架构实践
运维·数据库·redis
叶小鸡12 小时前
Java 篇-项目实战-AI 天机学堂(从 0 到 1)-day5
数据库·redis·缓存
IT策士12 小时前
Redis 从入门到精通:Python 操作 Redis
redis·python·bootstrap
我是谁??12 小时前
ubuntu22.04 通过docker部署vLLM(Qwen3-0.6B)大模型+New API+OpenWebUI
docker·容器·vllm