? ?对很多程序员来说,项目累积多了,每个项目需要不同版本的开发环境是非常正常的。此篇讲解使用docker-compose 安装多个版本的php环境,docker-compose 基础知识需自行了解。
? ?docker-compose.yml 文件配置。
? ??
version: '3.3'
services:
php72-fpm:
build: ./php72 // php72版本 (复制请把注释去掉)
ports:
- "9003:9000" // 由于底下另一版本占用9000端口,此处用9003映射
links:
- mysql-write:mysql-write // mysql容器连接
- redis-db:redis-db // redis容器连接
volumes: // 数据卷映射存储(自己没有的东西要去掉哦)
- ../Site:/data/www:rw
- ./php72/cert:/data/cert:ro
- ./php72/php-fpm.d:/usr/local/etc/php-fpm.d:rw
- ./php72/php-fpm.conf:/usr/local/etc/php-fpm.conf:ro
- ./php72/php-dev.ini:/usr/local/etc/php/php.ini:ro
- ../logs/php-fpm:/var/log/php-fpm:rw
- ./php72/.ssh:/home/www/.ssh:ro
- ./php72/supervisor.conf:/etc/supervisor/conf.d:ro
- ../logs/socket:/var/log/socket:rw
- ../logs/queue:/var/log/queue:rw
environment:
XDEBUG_CONFIG: remote_host=host.docker.internal
restart: always
command: php-fpm
php-fpm:
build: ./php74 // php74版本
ports:
- "9000:9000"
- "9501:9501"
- "9502:9502"
links:
- mysql-write:mysql-write
- redis-db:redis-db
volumes:
- ../Site:/data/www:rw
- ./php74/cert:/data/cert:ro
- ./php74/php-fpm.d:/usr/local/etc/php-fpm.d:rw
- ./php74/php-fpm.conf:/usr/local/etc/php-fpm.conf:ro
- ./php74/php-dev.ini:/usr/local/etc/php/php.ini:ro
- ../logs/php74-fpm:/var/log/php-fpm:rw
- ./php74/.ssh:/home/www/.ssh:ro
- ./php74/supervisor.conf:/etc/supervisor/conf.d:ro
- ../logs/socket:/var/log/socket:rw
- ../logs/queue:/var/log/queue:rw
environment:
XDEBUG_CONFIG: remote_host=host.docker.internal
restart: always
command: php-fpm
nginx:
build: ./nginx
depends_on:
- php-fpm
links:
- php-fpm:php-fpm
volumes:
- ../Site:/data/www:rw
- ./nginx/conf.d:/etc/nginx/conf.d:ro
- ./nginx/cert:/etc/nginx/cert:ro
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/phpcgi.conf:/etc/nginx/phpcgi.conf:ro
- ./nginx/fastcgi.conf:/etc/nginx/fastcgi.conf:ro
- ./nginx/pathinfo.conf:/etc/nginx/pathinfo.conf:ro
- ../logs/nginx:/var/log/nginx
ports:
- "80:80"
- "443:443"
- "8081:8081"
restart: always
command: nginx -g 'daemon off;'
mysql-write:
build: ./mysql-write
ports:
- "3306:3306"
volumes:
- ../data/mysql-write:/var/lib/mysql:rw
- ../logs/mysql-write:/var/lib/mysql-logs:rw
- ./mysql-write/my.cnf:/etc/mysql/my.cnf:ro
- ./mysql-write/conf.d:/etc/mysql/conf.d:ro
environment:
MYSQL_ROOT_PASSWORD: 666666
restart: always
command: "--character-set-server=utf8"
编辑完成,在docker-compose.yml文件的目录下,运行docker-compose up -d即可。
项目绑定对应php版本
在对应项目的nginx配置文件中配置如下:
server {
listen 80;
server_name sanwu.document.com;
root /data/www/cloud-document-server/public;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location ~ \.php(.*)$ {
fastcgi_pass php72-fpm:9000; // 绑定对应php版本
include pathinfo.conf;
include fastcgi.conf;
}
location @rewrite {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
}
location ~ /\.ht {
deny all;
}
}
?
|