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"]
相关推荐
Charlie_lll19 分钟前
RAG+ReAct 智能体深度重构|从「固定三步执行」到「动态思考-行动循环」
人工智能·spring boot·redis·后端·ai·重构
吉吉6119 分钟前
在 Windows 和 Linux 的 VSCode 中配置 PHP Debug
开发语言·php
袁袁袁袁满23 分钟前
Docker服务彻底清空的所有相关资源(容器、镜像、网络、数据卷等)
linux·运维·ubuntu·docker·容器·docker清空资源·docker停掉资源
skywalk816329 分钟前
Ubuntu22.04安装docker并启动 dnote服务
linux·ubuntu·docker·dnote
上天_去_做颗惺星 EVE_BLUE33 分钟前
Android设备与Mac/Docker全连接指南:有线到无线的完整方案
android·linux·macos·adb·docker·容器·安卓
leaf9z36 分钟前
docker镜像加速网站
docker·容器
Leon-zy1 小时前
Redis7.4.5集群部署3主3从
redis·分布式·缓存·云原生
nix.gnehc1 小时前
Anolis23 环境下 Docker 与私有 Harbor 仓库完整部署指南
运维·docker·容器
xiep14383335101 小时前
Ubuntu 24.04.3 LTS 搭建离线仓库安装docker-ce
linux·ubuntu·docker
catchadmin1 小时前
PHP 8.5 闭包和一等可调用对象进入常量表达式
php