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"]
相关推荐
momo学习版6 小时前
带你实现基于 Redis 的分布式 Session 管理
redis
ServBay1 天前
告别面条代码,PSL 5.0 重构 PHP 性能与安全天花板
后端·php
Sheffield3 天前
Docker的跨主机服务与其对应的优缺点
linux·网络协议·docker
Sheffield3 天前
Alpine是什么,为什么是Docker首选?
linux·docker·容器
马艳泽3 天前
win10下运行Start Broker and Proxy报错解决
docker
JaguarJack3 天前
FrankenPHP 原生支持 Windows 了
后端·php·服务端
BingoGo3 天前
FrankenPHP 原生支持 Windows 了
后端·php
JavaGuide4 天前
字节二面:Redis 能做消息队列吗?怎么实现?
redis·后端
用户13573999256604 天前
Windows 从 0 搭建 WSL2 原生 AI 开发环境:Codex + Docker + VSCode
docker