This commit is contained in:
2025-12-17 10:18:58 +08:00
commit ad4cb058fc
4112 changed files with 750772 additions and 0 deletions

5
docker/php/.env Normal file
View File

@@ -0,0 +1,5 @@
MYSQL_ROOT_PASSWORD=rootpassword
# 可选:你也可以在这里定义 MYSQL_DATABASE / MYSQL_USER / MYSQL_PASSWORD
MYSQL_DATABASE=shop_mallnew
MYSQL_USER=shop_mallnew
MYSQL_PASSWORD=shop_mallnew

87
docker/php/Dockerfile Normal file
View File

@@ -0,0 +1,87 @@
# 使用官方PHP镜像
FROM php:7.4.33-fpm
# 设置工作目录
WORKDIR /var/www/html
# 拷贝本地的 sources.list 文件以加速 apt-get
COPY ./sources.list /etc/apt/sources.list
# 复制Supervisor配置
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# 安装系统依赖
RUN apt-get update && apt-get install -y \
supervisor \
git \
curl \
vim \
libpng-dev \
libonig-dev \
libxml2-dev \
libssl-dev \
zip \
unzip \
libzip-dev \
default-mysql-client \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
iputils-ping \
&& rm -rf /var/lib/apt/lists/*
# 安装 PHP 扩展
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install \
pdo_mysql \
mysqli \
mbstring \
exif \
pcntl \
bcmath \
gd \
zip \
sockets
# 安装 Redis 扩展
RUN pecl install redis-5.3.7 && docker-php-ext-enable redis
# 安装Composer
COPY --from=composer:2.2.25 /usr/bin/composer /usr/bin/composer
# 验证安装
RUN composer --version
# 修改 PHP 配置
RUN echo "memory_limit=256M" > /usr/local/etc/php/conf.d/memory-limit.ini \
&& echo "upload_max_filesize=50M" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "post_max_size=50M" >> /usr/local/etc/php/conf.d/uploads.ini
# # 使用Composer安装项目依赖可选根据需要启用, 更多的时候,会出错,要在容器中执行操作)
# RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
# RUN composer install --no-dev --optimize-autoloader --working-dir=/var/www/html
# 暴露端口
EXPOSE 9000
############ 查看 cron 进程
## 查看 cron 进程
# ps aux | grep "think cron:schedule"
# # 精确查找
# pgrep -f "think cron:schedule"
# # 查看进程树
# pstree -p | grep -i cron
## 启动 cron 任务
# 守护进程模式
# nohup php think cron:schedule > /dev/null 2>&1 &
#######################################
# 启动Supervisor
# 添加在Dockerfile末尾CMD命令之前
COPY ./entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# 修改CMD命令
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

113
docker/php/entrypoint.sh Normal file
View File

@@ -0,0 +1,113 @@
#!/bin/bash
set -e
echo "=== ThinkPHP Docker权限初始化 ==="
# 定义应用根目录
APP_ROOT="/var/www/html"
# 获取正确的用户和组
if [ -n "$USER_ID" ] && [ -n "$GROUP_ID" ]; then
# 如果指定了用户ID修改www-data
usermod -u $USER_ID www-data
groupmod -g $GROUP_ID www-data
fi
echo "当前用户: $(whoami)"
echo "UID: $(id -u), GID: $(id -g)"
# 修复目录所有权和权限
fix_directory_permissions() {
local dir=$1
echo "修复PHP目录权限: $dir"
# 确保目录存在
mkdir -p "$dir"
# 设置所有权
chown -R www-data:www-data "$dir"
# 设置权限
chmod -R 775 "$dir"
# 设置setgid权限
chmod g+s "$dir"
# 尝试设置ACL如果支持
if command -v setfacl >/dev/null 2>&1; then
setfacl -dR -m u:www-data:rwx "$dir"
fi
find "$dir" -type d -exec chmod 775 {} \;
find "$dir" -type f -exec chmod 775 {} \;
find "$dir" -type d -exec chmod g+s {} \;
find "$dir" -type f -exec chmod g+s {} \;
# 设置umask
umask 0002
echo "$dir 权限设置完成, 目录权限: $(stat -c '%a %n' "$dir"), setgid权限: $(stat -c '%a %n' "$dir" | grep 's')"
}
# 处理所有需要权限的目录
directories=("runtime" "upload" "runtime/log" "runtime/cache" "runtime/temp")
for dir in "${directories[@]}"; do
fix_directory_permissions "$APP_ROOT/$dir"
done
# 验证权限
echo "=== 权限验证 ==="
echo "当前用户: $(whoami)"
echo "当前UID: $(id -u), GID: $(id -g)"
echo "当前umask: $(umask)"
# 验证www-data用户是否可以在runtime和upload目录下新建子目录
# 方法1使用sudo
if command -v sudo >/dev/null 2>&1; then
echo "使用sudo测试..."
if sudo -u www-data mkdir -p $APP_ROOT/runtime/log/test_dir 2>/dev/null; then
echo "✅ sudo: runtime目录创建子目录成功 [使用www-data用户]"
rm -rf $APP_ROOT/runtime/log/test_dir
else
echo "❌ sudo: runtime目录创建子目录失败 [使用www-data用户]"
fi
fi
# 方法2使用su
echo "使用su测试..."
if su -s /bin/sh -c "mkdir -p $APP_ROOT/runtime/log/test_dir" www-data 2>/dev/null; then
echo "✅ su: runtime目录创建子目录成功 [使用www-data用户]"
rm -rf $APP_ROOT/runtime/log/test_dir
else
echo "❌ su: runtime目录创建子目录失败 [使用www-data用户]"
fi
# 方法3使用runuser
if command -v runuser >/dev/null 2>&1; then
echo "使用runuser测试..."
if runuser -u www-data -- mkdir -p $APP_ROOT/runtime/log/test_dir 2>/dev/null; then
echo "✅ runuser: runtime目录创建子目录成功 [使用www-data用户]"
rm -rf $APP_ROOT/runtime/log/test_dir
else
echo "❌ runuser: runtime目录创建子目录失败 [使用www-data用户]"
fi
fi
# 检查www-data用户和组
echo "检查www-data用户..."
id www-data
groups www-data
# 检查目录的实际权限
echo "检查目录权限..."
ls -ld $APP_ROOT/runtime/log
ls -ld $APP_ROOT/runtime/cache
ls -ld $APP_ROOT/runtime/temp
ls -ld $APP_ROOT/upload
echo "=== 启动应用 ==="
# 执行原有的启动命令
exec "$@"

6
docker/php/php.ini Normal file
View File

@@ -0,0 +1,6 @@
display_errors = On
error_reporting = E_ALL
memory_limit = 512M
upload_max_filesize = 50M
post_max_size = 50M
opcache.enable=0 # 开发环境关闭opcache

6
docker/php/sources.list Normal file
View File

@@ -0,0 +1,6 @@
# deb http://snapshot.debian.org/archive/debian/20221114T000000Z bullseye main
deb https://mirrors.aliyun.com/debian/ bullseye main
# deb http://snapshot.debian.org/archive/debian-security/20221114T000000Z bullseye-security main
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
# deb http://snapshot.debian.org/archive/debian/20221114T000000Z bullseye-updates main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main

View File

@@ -0,0 +1,45 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=/var/run/supervisord.pid
[program:chmod]
command=/bin/bash -c "while true; do chmod -R 775 /var/www/html/runtime/ /var/www/html/upload/ 2>/dev/null || true; sleep 30; done"
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
[program:php-fpm]
command=php-fpm
autostart=true
autorestart=true
startretries=3
startsecs=1
stopasgroup=true
killasgroup=true
stdout_logfile=/var/log/supervisor/php-fpm.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stderr_logfile=/var/log/supervisor/php-fpm-error.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10
[program:think-cron]
command=php /var/www/html/think cron:schedule
process_name=%(program_name)s_%(process_num)02d
numprocs=1
autostart=true
autorestart=true
startretries=3
stdout_logfile=/var/log/supervisor/think-cron.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stderr_logfile=/var/log/supervisor/think-cron-error.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10
startsecs=3
stopwaitsecs=10

23
docker/php/xdebug.ini Normal file
View File

@@ -0,0 +1,23 @@
; Xdebug 配置
zend_extension=xdebug.so
; 基本配置
xdebug.mode=debug,develop
xdebug.start_with_request=yes
xdebug.discover_client_host=false
; 远程调试配置
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.idekey=VSCODE
; 日志配置(调试时开启)
xdebug.log=/tmp/xdebug.log
xdebug.log_level=7
; 性能分析(可选)
; xdebug.mode=profile
; xdebug.output_dir=/tmp/profiler
; 路径映射(在 VSCode 中配置更灵活)
xdebug.remote_connect_back=0