#tradewind:add mysql8; add wsl support; add readme
This commit is contained in:
90
README.md
Normal file
90
README.md
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
# PHP Docker 开发环境
|
||||||
|
|
||||||
|
一个完整的PHP开发环境,包含多版本PHP、数据库、缓存等服务。
|
||||||
|
|
||||||
|
## 服务列表
|
||||||
|
|
||||||
|
| 服务 | 端口 | 版本 | 说明 |
|
||||||
|
|------|------|------|------|
|
||||||
|
| Nginx | 80 | latest | Web服务器 |
|
||||||
|
| PHP 7.1 | 9000 | 7.1 | PHP-FPM |
|
||||||
|
| PHP 7.4 | 9000 | 7.4 | PHP-FPM |
|
||||||
|
| PHP 8.3 | 9000 | 8.3 | PHP-FPM |
|
||||||
|
| MySQL | 3306 | 5.7 | 数据库 |
|
||||||
|
| MySQL8 | 3306 | 8.0 | 数据库 |
|
||||||
|
| Redis | 6379 | latest | 缓存 |
|
||||||
|
| Python | 8000 | latest | Python环境 |
|
||||||
|
| Node.js | - | latest | Node.js环境 |
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### 1. 环境变量配置
|
||||||
|
创建 `.env` 文件并设置以下变量:
|
||||||
|
```bash
|
||||||
|
LOCAL_CODE_ROOT=/path/to/your/code # 本地代码目录
|
||||||
|
PROJECT_PATH=/path/to/your/project # 项目路径
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 启动服务
|
||||||
|
|
||||||
|
**普通环境:**
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
**WSL环境:**
|
||||||
|
```bash
|
||||||
|
docker-compose -f docker-compose.yml -f docker-compose.wsl.yml up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 验证服务
|
||||||
|
```bash
|
||||||
|
docker-compose ps
|
||||||
|
```
|
||||||
|
|
||||||
|
## 使用说明
|
||||||
|
|
||||||
|
### Nginx配置
|
||||||
|
- 配置文件位置:`./nginx/conf.d/`
|
||||||
|
- 参考示例:`./nginx/conf.d/example.conf`
|
||||||
|
- 网站根目录:`/var/www/http`
|
||||||
|
|
||||||
|
### PHP版本切换
|
||||||
|
在Nginx配置中修改 `fastcgi_pass` 参数:
|
||||||
|
- PHP 7.1:`fastcgi_pass php71:9000;`
|
||||||
|
- PHP 7.4:`fastcgi_pass php74:9000;`
|
||||||
|
- PHP 8.3:`fastcgi_pass php83:9000;`
|
||||||
|
|
||||||
|
### 数据库连接
|
||||||
|
- **MySQL 5.7**:`mysql:3306`,用户名/密码:`root/root`
|
||||||
|
- **MySQL 8.0**:`mysql8:3306`,用户名/密码:`root/root`
|
||||||
|
- **Redis**:`redis:6379`
|
||||||
|
|
||||||
|
### 常用命令
|
||||||
|
|
||||||
|
**查看日志:**
|
||||||
|
```bash
|
||||||
|
docker-compose logs -f [服务名]
|
||||||
|
```
|
||||||
|
|
||||||
|
**进入容器:**
|
||||||
|
```bash
|
||||||
|
docker exec -it [容器名] bash
|
||||||
|
```
|
||||||
|
|
||||||
|
**重启服务:**
|
||||||
|
```bash
|
||||||
|
docker-compose restart [服务名]
|
||||||
|
```
|
||||||
|
|
||||||
|
**停止所有服务:**
|
||||||
|
```bash
|
||||||
|
docker-compose down
|
||||||
|
```
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
1. 确保本地80、3306、6379端口未被占用
|
||||||
|
2. WSL环境需要额外的挂载配置
|
||||||
|
3. Xdebug已预配置,端口9003
|
||||||
|
4. 日志文件保存在 `./log/` 目录
|
12
docker-compose.wsl.yml
Normal file
12
docker-compose.wsl.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# docker-compose.wsl.yml(WSL 专用挂载)
|
||||||
|
version: '3.8'
|
||||||
|
services:
|
||||||
|
php71:
|
||||||
|
volumes:
|
||||||
|
- /mnt/d:/mnt/d # WSL 特有挂载
|
||||||
|
php74:
|
||||||
|
volumes:
|
||||||
|
- /mnt/d:/mnt/d # WSL 特有挂载
|
||||||
|
php83:
|
||||||
|
volumes:
|
||||||
|
- /mnt/d:/mnt/d # WSL 特有挂载
|
@ -42,7 +42,7 @@ services:
|
|||||||
- ./php7.4/sources.list:/etc/apt/sources.list
|
- ./php7.4/sources.list:/etc/apt/sources.list
|
||||||
- ./php7.4/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
|
- ./php7.4/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
|
||||||
- ./php7.4/php.ini:/usr/local/etc/php/php.ini
|
- ./php7.4/php.ini:/usr/local/etc/php/php.ini
|
||||||
- ${LOCAL_CODE_ROOT}:/var/www/http
|
- ${LOCAL_CODE_ROOT}:/var/www
|
||||||
networks:
|
networks:
|
||||||
- server
|
- server
|
||||||
container_name: php74
|
container_name: php74
|
||||||
@ -55,7 +55,7 @@ services:
|
|||||||
- ./php8.3/sources.list:/etc/apt/sources.list
|
- ./php8.3/sources.list:/etc/apt/sources.list
|
||||||
- ./php8.3/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
|
- ./php8.3/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
|
||||||
- ./php8.3/php.ini:/usr/local/etc/php/php.ini
|
- ./php8.3/php.ini:/usr/local/etc/php/php.ini
|
||||||
- ${LOCAL_CODE_ROOT}:/var/www/http
|
- ${LOCAL_CODE_ROOT}:/var/www
|
||||||
networks:
|
networks:
|
||||||
- server
|
- server
|
||||||
container_name: php83
|
container_name: php83
|
||||||
@ -74,6 +74,19 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "3306:3306"
|
- "3306:3306"
|
||||||
container_name: mysql
|
container_name: mysql
|
||||||
|
mysql8:
|
||||||
|
build:
|
||||||
|
context: mysql8/
|
||||||
|
dockerfile: dockerfile
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: root
|
||||||
|
command: --default-authentication-plugin=mysql_native_password
|
||||||
|
networks:
|
||||||
|
- server
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
|
container_name: mysql8
|
||||||
redis:
|
redis:
|
||||||
build:
|
build:
|
||||||
context: ./redis/
|
context: ./redis/
|
||||||
|
1
mysql8/dockerfile
Normal file
1
mysql8/dockerfile
Normal file
@ -0,0 +1 @@
|
|||||||
|
FROM mysql:8.0
|
10
mysql8/sources.list
Normal file
10
mysql8/sources.list
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
|
||||||
|
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
|
||||||
|
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
|
||||||
|
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
|
||||||
|
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
|
||||||
|
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
|
||||||
|
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
|
||||||
|
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
|
||||||
|
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
|
||||||
|
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
|
@ -8,7 +8,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
fastcgi_pass php71:9000;
|
fastcgi_pass php74:9000;
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
|
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
|
||||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
FROM php:7.4-fpm
|
FROM php:7.4-fpm
|
||||||
|
|
||||||
ARG PROJECT_PATH
|
RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list
|
||||||
|
|
||||||
WORKDIR ${PROJECT_PATH}
|
|
||||||
|
|
||||||
RUN sed -i "s@http://deb.debian.org@http://mirrors.tencent.com@g" /etc/apt/sources.list
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
git \
|
git \
|
||||||
@ -17,6 +13,8 @@ RUN apt-get update && apt-get install -y \
|
|||||||
libxml2-dev \
|
libxml2-dev \
|
||||||
libicu-dev \
|
libicu-dev \
|
||||||
libjpeg62-turbo-dev \
|
libjpeg62-turbo-dev \
|
||||||
|
libssl-dev \
|
||||||
|
librdkafka-dev \
|
||||||
&& docker-php-ext-configure intl \
|
&& docker-php-ext-configure intl \
|
||||||
&& docker-php-ext-configure pcntl --enable-pcntl \
|
&& docker-php-ext-configure pcntl --enable-pcntl \
|
||||||
&& docker-php-ext-install -j$(nproc) \
|
&& docker-php-ext-install -j$(nproc) \
|
||||||
@ -33,11 +31,13 @@ RUN apt-get update && apt-get install -y \
|
|||||||
&& pecl install \
|
&& pecl install \
|
||||||
redis \
|
redis \
|
||||||
xdebug-3.1.6 \
|
xdebug-3.1.6 \
|
||||||
# mongodb \
|
mongodb-1.12.0 \
|
||||||
|
rdkafka-4.1.2 \
|
||||||
&& docker-php-ext-enable \
|
&& docker-php-ext-enable \
|
||||||
redis \
|
redis \
|
||||||
xdebug \
|
xdebug \
|
||||||
# mongodb \
|
mongodb \
|
||||||
|
rdkafka \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& apt-get autoclean
|
&& apt-get autoclean
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
FROM php:8.3-fpm
|
FROM php:8.3-fpm
|
||||||
|
|
||||||
ARG PROJECT_PATH
|
RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list.d/debian.sources
|
||||||
|
|
||||||
WORKDIR ${PROJECT_PATH}
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
git \
|
git \
|
||||||
|
Reference in New Issue
Block a user