php-nginx-redis环境,适应各种配置的vps
4.4K
基于 Alpine Linux 构建的 Docker PHP-FPM 8.4 & Nginx 1.26 容器镜像示例。
仓库地址: https://github.com/vbskycn/php-nginx
ondemand进程管理器)docker logs -f <容器名称>查看)这个容器镜像的目标是提供一个在容器中运行Nginx和PHP-FPM的示例,专门针对512M VPS进行优化,遵循最佳实践,易于理解和修改以满足您的需求。特别适合资源受限的小型服务器环境。如你需要可以自行调整并重新编译
ondemand模式,按需创建进程,空闲时自动回收启动Docker容器:(不加变量为默认优化1H512M机器,直接使用就行)
docker run -p 80:8080 zhoujie218/php-nginx:latest
访问以下地址:
docker run -p 80:8080 -v ~/my-codebase:/var/www/html zhoujie218/php-nginx:latest
创建 docker-compose.yml:
version: '3.8'
services:
php-nginx:
image: zhoujie218/php-nginx:latest
ports:
- "80:8080"
volumes:
- ./src:/var/www/html
environment:
- PHP_MEMORY_LIMIT=128M
restart: unless-stopped
启动服务:
docker-compose up -d
支持通过环境变量自定义配置,适应不同设备规格。如果不设置环境变量,将使用512M VPS的默认优化配置。
| 变量名 | 默认值 | 说明 |
|---|---|---|
PHP_MEMORY_LIMIT | 64M | PHP内存限制 |
PHP_FPM_PM_MODE | ondemand | PHP-FPM进程管理模式 |
PHP_FPM_MAX_CHILDREN | 20 | 最大子进程数 |
OPCACHE_ENABLE | 1 | 是否启用OPcache |
OPCACHE_MEMORY_CONSUMPTION | 32 | OPcache内存大小(MB) |
REDIS_MAXMEMORY | 64mb | Redis最大内存 |
NGINX_WORKER_PROCESSES | auto | Nginx工作进程数 |
完整的环境变量配置说明请参考 环境变量配置指南
1G内存服务器配置示例:
version: '3.8'
services:
php-nginx:
image: zhoujie218/php-nginx:latest
ports:
- "80:8080"
volumes:
- ./src:/var/www/html
environment:
- PHP_MEMORY_LIMIT=128M
- OPCACHE_MEMORY_CONSUMPTION=64
- PHP_FPM_MAX_CHILDREN=40
- REDIS_MAXMEMORY=128mb
- NGINX_WORKER_PROCESSES=2
restart: unless-stopped
2G内存服务器配置示例:
version: '3.8'
services:
php-nginx:
image: zhoujie218/php-nginx:latest
ports:
- "80:8080"
volumes:
- ./src:/var/www/html
environment:
- PHP_MEMORY_LIMIT=256M
- OPCACHE_MEMORY_CONSUMPTION=128
- PHP_FPM_MAX_CHILDREN=60
- REDIS_MAXMEMORY=256mb
- NGINX_WORKER_PROCESSES=2
restart: unless-stopped
小内存机器配置示例:
默认绑定所有域名
docker stop php-nginx
docker rm php-nginx
docker run -d \
--name php-nginx \
--restart=always \
-p 80:8080 \
-e PHP_MEMORY_LIMIT=64M \
-e PHP_DISPLAY_ERRORS=Off \
-e PHP_MAX_EXECUTION_TIME=30 \
-e OPCACHE_ENABLE=1 \
-e OPCACHE_MEMORY_CONSUMPTION=32 \
-e PHP_FPM_PM_MODE=ondemand \
-e PHP_FPM_MAX_CHILDREN=20 \
-e REDIS_MAXMEMORY=64mb \
-e NGINX_WORKER_PROCESSES=1 \
-e NGINX_WORKER_CONNECTIONS=1024 \
zhoujie218/php-nginx:latest
主要或次要更改总是作为发布版本发布,并附有相应的变更日志。
当前版本:1.1.47
latest标签每周自动更新,包含Alpine Linux的最新补丁。
本项目支持两种配置方式:环境变量配置(推荐)和配置文件挂载。
通过环境变量可以灵活配置所有关键参数,无需修改配置文件:
# 基本配置示例
docker run -d \
--name php-nginx \
-p 80:8080 \
-e PHP_MEMORY_LIMIT=128M \
-e PHP_FPM_MAX_CHILDREN=40 \
-e OPCACHE_MEMORY_CONSUMPTION=64 \
-e REDIS_MAXMEMORY=128mb \
zhoujie218/php-nginx:latest
优势:
详细的环境变量配置说明请参考 环境变量配置指南
如果需要自定义配置文件,可以通过挂载方式覆盖默认配置:
创建 nginx-custom.conf:
server {
listen 8080;
server_name localhost;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
挂载配置:
# Linux/macOS
docker run -v "$(pwd)/nginx-custom.conf:/etc/nginx/conf.d/default.conf" zhoujie218/php-nginx:latest
# Windows PowerShell
docker run -v "${PWD}/nginx-custom.conf:/etc/nginx/conf.d/default.conf" zhoujie218/php-nginx:latest
创建 php-custom.ini:
; 自定义PHP配置
memory_limit = 256M
max_execution_time = 60
upload_max_filesize = 10M
post_max_size = 10M
挂载配置:
# Linux/macOS
docker run -v "$(pwd)/php-custom.ini:/etc/php84/conf.d/99-custom.ini" zhoujie218/php-nginx:latest
# Windows PowerShell
docker run -v "${PWD}/php-custom.ini:/etc/php84/conf.d/99-custom.ini" zhoujie218/php-nginx:latest
创建 php-fpm-custom.conf:
[www]
pm = dynamic
pm.max_children = 100
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
挂载配置:
# Linux/macOS
docker run -v "$(pwd)/php-fpm-custom.conf:/etc/php84/php-fpm.d/www.conf" zhoujie218/php-nginx:latest
# Windows PowerShell
docker run -v "${PWD}/php-fpm-custom.conf:/etc/php84/php-fpm.d/www.conf" zhoujie218/php-nginx:latest
GET /redis.php?action=get_key_info&key={key_name}
GET /redis.php?action=delete_key&key={key_name}
GET /admin.php
/fpm-status/fpm-ping要修改此容器以满足您的特定需求,请查看以下文档:
本项目基于TrafeX/docker-php-nginx 进行优化和改进,感谢原作@TrafeX 提供的优秀基础项目
Content type
Image
Digest
sha256:baef8adc7…
Size
44.1 MB
Last updated
8 months ago
docker pull zhoujie218/php-nginx