Skip to content

Commit

Permalink
[feat] v1.4
Browse files Browse the repository at this point in the history
## Feature
1. support `PHP 8.1.x`
2. `nginx` build form Dockerfile

## Dependencies
1. `swoole` To 4.8.5
2. `redis` To 5.3.5
  • Loading branch information
telanflow committed Dec 29, 2021
1 parent cc3acda commit 98703c7
Show file tree
Hide file tree
Showing 33 changed files with 6,474 additions and 25 deletions.
1 change: 1 addition & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ ELASTICSEARCH_PLUGINS=analysis-ik,analysis-pinyin
PHP56_FPM_PORT=9056
PHP74_FPM_PORT=9074
PHP80_FPM_PORT=9080
PHP81_FPM_PORT=9081

###################### SUPERVISOR_PHP
SUPERVISOR_PHP_VERSION=7.4.1
Expand Down
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DNMP 1.3.2
# DNMP 1.4

DNMP 可以构建出基于 Docker 的 PHP 开发环境,其优势有在短时间内随意构建不同版本的相关服务、环境统一分布在不同服务器等,使开发者能够更专注于开发业务本身。

Expand All @@ -14,8 +14,9 @@ DNMP 可以构建出基于 Docker 的 PHP 开发环境,其优势有在短时

* Ningx:latest
* PHP56:php-fpm 5.6.x `composer:1.8.0 swoole:1.10.5 redis:4.3.0`
* PHP74:php-fpm 7.4.x `composer:2.1.11 swoole:4.8.3 redis:5.3.4`
* PHP80:php-fpm 8.0.x `composer:2.1.11 swoole:4.8.3 redis:5.3.4`
* PHP74:php-fpm 7.4.x `composer:2.1.11 swoole:4.8.5 redis:5.3.5`
* PHP80:php-fpm 8.0.x `composer:2.1.11 swoole:4.8.5 redis:5.3.5`
* PHP81:php-fpm 8.1.x `composer:2.1.11 swoole:4.8.5 redis:5.3.5`
* MySQL:5.7
* Redis:latest `默认密码:dnmp`
* Mogodb: latest `默认验证数据库:admin;账号:admin;密码:admin`
Expand All @@ -28,15 +29,15 @@ DNMP 可以构建出基于 Docker 的 PHP 开发环境,其优势有在短时
|----/config 配置文件目录
|----/data 持久化数据目录
|----/www WEB文件目录
|----/.env-example 配置文件
|----/.env-example 配置文件示例
|----/docker-compose.yml docker compose 配置文件

## 开始安装

没有安装 Docker 的同学移步 [安装教程](https://github.com/telanflow/dnmp.git#安装-docker-及相关工具),如果你有足够的时间强烈建议通读 [Docker — 从入门到实践](https://yeasy.gitbooks.io/docker_practice/content/)

cd ~/
git clone https://github.com/telanflow/dnmp.git
git clone --depth 1 https://github.com/telanflow/dnmp.git

cd dnmp
cp .env-example .env
Expand All @@ -48,10 +49,10 @@ DNMP 可以构建出基于 Docker 的 PHP 开发环境,其优势有在短时
sudo docker-compose up --build -d

# 构建单个镜像并启动容器
sudo docker-compose up --build -d [nginx|php56|php74|php8 ...]
sudo docker-compose up --build -d [nginx|php56|php74|php80 ...]

# 构建单个镜像
sudo docker-compose build --no-cache [nginx|php56|php74|php8 ...]
sudo docker-compose build --no-cache [nginx|php56|php74|php80 ...]

> 📢 注意:dnmp部署完成后,需要修改redis服务的密码`config/redis/redis.conf 设置 requirepass dnmp(替换成你自己的密码)`
Expand All @@ -63,19 +64,19 @@ DNMP 可以构建出基于 Docker 的 PHP 开发环境,其优势有在短时
sudo docker-compose ps

# 启动部分服务在后边加服务名,不加表示启动所有,-d 表示在后台运行
sudo docker-compose up -d [nginx|php56|php74|php8 ...]
sudo docker-compose up -d [nginx|php56|php74|php80 ...]

# 启动容器
sudo docker-compose start [nginx|php56|php74|php8 ...]
sudo docker-compose start [nginx|php56|php74|php80 ...]

# 停止容器
sudo docker-compose stop [nginx|php56|php74|php8 ...]
sudo docker-compose stop [nginx|php56|php74|php80 ...]

# 重启容器
sudo docker-compose restart [nginx|php56|php74|php8 ...]
sudo docker-compose restart [nginx|php56|php74|php80 ...]

# 停止并删除相关的容器
sudo docker-compose down [nginx|php56|php74|php8 ...]
sudo docker-compose down [nginx|php56|php74|php80 ...]

# 删除所有未运行的容器
sudo docker rm $(sudo docker ps -a -q)
Expand All @@ -90,7 +91,7 @@ DNMP 可以构建出基于 Docker 的 PHP 开发环境,其优势有在短时
sudo docker system prune

# 进入容器
docker exec -it [dnmp-nginx|dnmp-redis|dnmp-php74|dnmp-php8| ...] bash
docker exec -it [dnmp-nginx|dnmp-redis|dnmp-php74|dnmp-php80| ...] bash

更多可通过 `sudo docker -h` 或者 `sudo docker-compose -h` 查看

Expand Down Expand Up @@ -119,7 +120,7 @@ DNMP 可以构建出基于 Docker 的 PHP 开发环境,其优势有在短时

# 1、更改对应的 dnmp/build/php/Dockerfile
# 2、重新构建镜像
sudo docker-compose build --no-cache [php56|php74|php8 ...]
sudo docker-compose build --no-cache [php56|php74|php80 ...]

### 如何在 php 里连接 MySQL 和 Redis?

Expand Down Expand Up @@ -184,8 +185,5 @@ DaoCloud 加速器:http://guide.daocloud.io/dcs/daocloud-9153151.html

腾讯云加速器:https://www.qcloud.com/document/product/457/7207

### 鸣谢
[Docker LNMP 3.2](https://github.com/exc-soft/docker-lnmp)

### License
MIT
4 changes: 2 additions & 2 deletions build/php74/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ COPY resource /home/resource
ARG CHANGE_SOURCE=true
ARG TIME_ZONE=UTC

ARG SWOOLE=swoole-4.8.3.tgz
ARG REDIS=redis-5.3.4.tgz
ARG SWOOLE=swoole-4.8.5.tgz
ARG REDIS=redis-5.3.5.tgz
ARG MCRYPT=mcrypt-1.0.4.tgz

ENV TIME_ZONE=${TIME_ZONE} LC_ALL=C.UTF-8
Expand Down
Binary file removed build/php74/resource/redis-5.3.4.tgz
Binary file not shown.
Binary file added build/php74/resource/redis-5.3.5.tgz
Binary file not shown.
Binary file removed build/php74/resource/swoole-4.8.3.tgz
Binary file not shown.
Binary file added build/php74/resource/swoole-4.8.5.tgz
Binary file not shown.
Binary file removed build/php74/resource/xdebug-3.0.4.tgz
Binary file not shown.
Binary file added build/php74/resource/xdebug-3.1.2.tgz
Binary file not shown.
4 changes: 2 additions & 2 deletions build/php80/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ COPY resource /home/resource
ARG CHANGE_SOURCE=true
ARG TIME_ZONE=UTC

ARG SWOOLE=swoole-4.8.3.tgz
ARG REDIS=redis-5.3.4.tgz
ARG SWOOLE=swoole-4.8.5.tgz
ARG REDIS=redis-5.3.5.tgz
ARG MCRYPT=mcrypt-1.0.4.tgz

ENV TIME_ZONE=${TIME_ZONE} LC_ALL=C.UTF-8
Expand Down
Binary file removed build/php80/resource/redis-5.3.4.tgz
Binary file not shown.
Binary file added build/php80/resource/redis-5.3.5.tgz
Binary file not shown.
Binary file removed build/php80/resource/swoole-4.8.3.tgz
Binary file not shown.
Binary file added build/php80/resource/swoole-4.8.5.tgz
Binary file not shown.
Binary file removed build/php80/resource/xdebug-3.0.4.tgz
Binary file not shown.
Binary file added build/php80/resource/xdebug-3.1.2.tgz
Binary file not shown.
105 changes: 105 additions & 0 deletions build/php81/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
FROM php:8.1-fpm-buster

COPY resource /home/resource

ARG CHANGE_SOURCE=true
ARG TIME_ZONE=UTC

ARG SWOOLE=swoole-4.8.5.tgz
ARG REDIS=redis-5.3.5.tgz
ARG MCRYPT=mcrypt-1.0.4.tgz

ENV TIME_ZONE=${TIME_ZONE} LC_ALL=C.UTF-8

RUN set -eux; \
# ⬇ 修改时区
ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime ; \
echo $TIME_ZONE > /etc/timezone ; \
\
# ⬇ 安装 PHP Composer
mv /home/resource/composer.phar /usr/local/bin/composer ; \
chmod 755 /usr/local/bin/composer ; \
\
# ⬇ 替换源
rm -rf /etc/apt/sources.list.d/buster.list ; \
if [ ${CHANGE_SOURCE} = true ]; then \
mv /etc/apt/sources.list /etc/apt/source.list.bak; \
mv /home/resource/sources.list /etc/apt/sources.list; \
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ ; \
fi; \
\
# ⬇ 更新、安装基础组件
apt-get update; \
apt-get upgrade -y; \
apt-get install -y --allow-remove-essential --no-install-recommends \
# tools
wget \
zip \
unzip \
git \
cron \
vim \
iputils-ping \
telnet \
net-tools \
\
libmagickwand-dev \
libz-dev \
# intl
libicu-dev \
# bz2
libbz2-dev \
# zip
libzip-dev \
# ldap
libldb-dev \
libldap2-dev \
# mcrypt
libmcrypt-dev \
# other
libtinfo5 \
libpq-dev \
libjpeg-dev \
libpng-dev \
libfreetype6-dev \
libssl-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
zlib1g-dev \
libpng-dev \
procps \
libmhash-dev \
librabbitmq-dev \
ntpdate ;

####################################################################################
# 安装 PHP 扩展
####################################################################################

RUN docker-php-ext-configure gd \
--with-freetype-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ ; \
docker-php-ext-install -j$(nproc) gd intl pdo_mysql ldap mysqli bz2 zip sockets pgsql pdo_pgsql bcmath soap pcntl; \
# \
# ⬇ XDebug
# pecl install /home/resource/$XDEBUG ; \
\
# ⬇ Imagick
pecl install imagick && docker-php-ext-enable imagick; \
\
# ⬇ Redis
pecl install /home/resource/$REDIS ; \
echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini ; \
\
# ⬇ Swoole
pecl install /home/resource/$SWOOLE ; \
echo "extension=swoole.so" > /usr/local/etc/php/conf.d/swoole.ini ; \
\
# ⬇ Mcrypt
pecl install /home/resource/$MCRYPT ; \
echo "extension=mcrypt.so" > /usr/local/etc/php/conf.d/mcrypt.ini ; \
\
# ⬇ 清理
rm -rf /var/lib/apt/lists/* ; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false ; \
rm -rf /home/resource ;
Binary file added build/php81/resource/composer.phar
Binary file not shown.
Binary file added build/php81/resource/mcrypt-1.0.4.tgz
Binary file not shown.
Binary file added build/php81/resource/redis-5.3.5.tgz
Binary file not shown.
4 changes: 4 additions & 0 deletions build/php81/resource/sources.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deb http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb http://mirrors.aliyun.com/debian-security buster/updates main
deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
Binary file added build/php81/resource/swoole-4.8.5.tgz
Binary file not shown.
Binary file added build/php81/resource/xdebug-3.1.2.tgz
Binary file not shown.
6 changes: 6 additions & 0 deletions config/nginx/rewrite/php81.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
location ~ \.php$ {
fastcgi_pass dnmp-php81:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
2 changes: 1 addition & 1 deletion config/nginx/vhost/localhost.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ server {
root /etc/nginx/html;

# include /etc/nginx/rewrite/wordpress.conf;
include /etc/nginx/rewrite/php80.conf;
include /etc/nginx/rewrite/php81.conf;

access_log /var/log/nginx/localhost-access.log;
error_log /var/log/nginx/localhost-error.log;
Expand Down
5 changes: 3 additions & 2 deletions config/nginx/vhost/localhost.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ server {

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
# Or include php56.conf php74.conf php8.conf
# Or include php56.conf php74.conf php80.conf php81.conf
#
# include /etc/nginx/rewrite/php56.conf;
# include /etc/nginx/rewrite/php74.conf;
# include /etc/nginx/rewrite/php80.conf;
# include /etc/nginx/rewrite/php81.conf;
#
location ~ \.php$ {
fastcgi_pass php80:9000;
fastcgi_pass php81:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
Expand Down
Loading

0 comments on commit 98703c7

Please sign in to comment.