Compare commits
2 Commits
e818f9a71d
...
9ec8058bc5
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ec8058bc5 | |||
|
|
df43e75dff |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -2,4 +2,6 @@
|
||||
*.iml
|
||||
log
|
||||
.env
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
.vscode
|
||||
data
|
||||
|
||||
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"augment.advanced": {
|
||||
|
||||
}
|
||||
}
|
||||
122
README.md
Normal file
122
README.md
Normal file
@@ -0,0 +1,122 @@
|
||||
# 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
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### Laravel权限问题
|
||||
如果遇到Laravel日志文件权限错误,执行以下步骤:
|
||||
|
||||
1. **重新构建PHP容器**(已配置用户ID匹配):
|
||||
```bash
|
||||
docker-compose build php83
|
||||
docker-compose up -d php83
|
||||
```
|
||||
|
||||
2. **设置Laravel目录权限**:
|
||||
```bash
|
||||
# 进入PHP容器
|
||||
docker exec -it php83 bash
|
||||
|
||||
# 设置storage和cache目录权限
|
||||
chown -R www-data:www-data /var/www/mono-be/storage
|
||||
chown -R www-data:www-data /var/www/mono-be/bootstrap/cache
|
||||
chmod -R 775 /var/www/mono-be/storage
|
||||
chmod -R 775 /var/www/mono-be/bootstrap/cache
|
||||
```
|
||||
|
||||
3. **或者在宿主机直接设置**:
|
||||
```bash
|
||||
# 在WSL中执行
|
||||
sudo chown -R 1000:1000 /path/to/mono-be/storage
|
||||
sudo chown -R 1000:1000 /path/to/mono-be/bootstrap/cache
|
||||
chmod -R 775 /path/to/mono-be/storage
|
||||
chmod -R 775 /path/to/mono-be/bootstrap/cache
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
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 特有挂载
|
||||
@@ -5,17 +5,34 @@ services:
|
||||
build:
|
||||
context: ./nginx/
|
||||
dockerfile: dockerfile
|
||||
ports:
|
||||
- "80:80"
|
||||
networks:
|
||||
- server
|
||||
network_mode: host
|
||||
volumes:
|
||||
- ./nginx/conf.d:/etc/nginx/conf.d
|
||||
- ./nginx/sources.list:/etc/apt/sources.list
|
||||
- ${LOCAL_CODE_ROOT}:/var/www/http
|
||||
- /var/www:/var/www
|
||||
- ./log/nginx:/var/log/nginx
|
||||
container_name: nginx
|
||||
restart: always
|
||||
profiles:
|
||||
- nginx-host
|
||||
nginx-bridge:
|
||||
build:
|
||||
context: ./nginx/
|
||||
dockerfile: dockerfile
|
||||
volumes:
|
||||
- ./nginx/conf.d:/etc/nginx/conf.d
|
||||
- ./nginx/sources.list:/etc/apt/sources.list
|
||||
- /var/www:/var/www
|
||||
- ./log/nginx:/var/log/nginx
|
||||
container_name: nginx
|
||||
restart: always
|
||||
networks:
|
||||
- server
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
profiles:
|
||||
- nginx-bridge
|
||||
php71:
|
||||
build:
|
||||
context: ./php7.1/
|
||||
@@ -42,7 +59,7 @@ services:
|
||||
- ./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/php.ini:/usr/local/etc/php/php.ini
|
||||
- ${LOCAL_CODE_ROOT}:/var/www/http
|
||||
- ${LOCAL_CODE_ROOT}:/var/www
|
||||
networks:
|
||||
- server
|
||||
container_name: php74
|
||||
@@ -55,7 +72,7 @@ services:
|
||||
- ./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/php.ini:/usr/local/etc/php/php.ini
|
||||
- ${LOCAL_CODE_ROOT}:/var/www/http
|
||||
- ${LOCAL_CODE_ROOT}:/var/www
|
||||
networks:
|
||||
- server
|
||||
container_name: php83
|
||||
@@ -67,6 +84,10 @@ services:
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: root
|
||||
TZ: Asia/Shanghai
|
||||
volumes:
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- ./data/mysql:/var/lib/mysql
|
||||
command: --default-authentication-plugin=mysql_native_password
|
||||
# platform: linux/amd64 # apple silicon
|
||||
networks:
|
||||
@@ -74,6 +95,23 @@ services:
|
||||
ports:
|
||||
- "3306:3306"
|
||||
container_name: mysql
|
||||
mysql8:
|
||||
build:
|
||||
context: mysql8/
|
||||
dockerfile: dockerfile
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: root
|
||||
TZ: Asia/Shanghai
|
||||
volumes:
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- ./data/mysql8:/var/lib/mysql
|
||||
command: --default-authentication-plugin=mysql_native_password
|
||||
networks:
|
||||
- server
|
||||
ports:
|
||||
- "3306:3306"
|
||||
container_name: mysql8
|
||||
redis:
|
||||
build:
|
||||
context: ./redis/
|
||||
@@ -110,4 +148,4 @@ services:
|
||||
ipc: host
|
||||
container_name: node
|
||||
networks:
|
||||
server:
|
||||
server:
|
||||
|
||||
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$ {
|
||||
fastcgi_pass php71:9000;
|
||||
fastcgi_pass php74:9000;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
FROM php:7.4-fpm
|
||||
|
||||
ARG PROJECT_PATH
|
||||
|
||||
WORKDIR ${PROJECT_PATH}
|
||||
|
||||
RUN sed -i "s@http://deb.debian.org@http://mirrors.tencent.com@g" /etc/apt/sources.list
|
||||
RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
git \
|
||||
@@ -17,6 +13,8 @@ RUN apt-get update && apt-get install -y \
|
||||
libxml2-dev \
|
||||
libicu-dev \
|
||||
libjpeg62-turbo-dev \
|
||||
libssl-dev \
|
||||
librdkafka-dev \
|
||||
&& docker-php-ext-configure intl \
|
||||
&& docker-php-ext-configure pcntl --enable-pcntl \
|
||||
&& docker-php-ext-install -j$(nproc) \
|
||||
@@ -33,11 +31,13 @@ RUN apt-get update && apt-get install -y \
|
||||
&& pecl install \
|
||||
redis \
|
||||
xdebug-3.1.6 \
|
||||
# mongodb \
|
||||
mongodb-1.12.0 \
|
||||
rdkafka-4.1.2 \
|
||||
&& docker-php-ext-enable \
|
||||
redis \
|
||||
xdebug \
|
||||
# mongodb \
|
||||
mongodb \
|
||||
rdkafka \
|
||||
&& apt-get clean \
|
||||
&& apt-get autoclean
|
||||
|
||||
|
||||
BIN
php8.3/composer.phar
Normal file
BIN
php8.3/composer.phar
Normal file
Binary file not shown.
@@ -1,8 +1,11 @@
|
||||
FROM php:8.3-fpm
|
||||
|
||||
ARG PROJECT_PATH
|
||||
COPY redis-6.0.2.tgz /tmp/redis.tgz
|
||||
COPY xdebug-3.4.3.tgz /tmp/xdebug.tgz
|
||||
COPY rdkafka-6.0.5.tgz /tmp/rdkafka.tgz
|
||||
COPY composer.phar /usr/local/bin/composer
|
||||
|
||||
WORKDIR ${PROJECT_PATH}
|
||||
RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list.d/debian.sources
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
git \
|
||||
@@ -14,7 +17,8 @@ RUN apt-get update && apt-get install -y \
|
||||
libfreetype6-dev \
|
||||
libxml2-dev \
|
||||
libicu-dev \
|
||||
libjpeg62-turbo-dev \
|
||||
libssl-dev \
|
||||
librdkafka-dev \
|
||||
&& docker-php-ext-configure intl \
|
||||
&& docker-php-ext-configure pcntl --enable-pcntl \
|
||||
&& docker-php-ext-install -j$(nproc) \
|
||||
@@ -29,11 +33,14 @@ RUN apt-get update && apt-get install -y \
|
||||
soap \
|
||||
pcntl \
|
||||
&& pecl install \
|
||||
redis \
|
||||
xdebug \
|
||||
/tmp/redis.tgz \
|
||||
/tmp/xdebug.tgz \
|
||||
/tmp/rdkafka.tgz \
|
||||
&& docker-php-ext-enable \
|
||||
redis \
|
||||
xdebug \
|
||||
rdkafka \
|
||||
&& rm -f /tmp/redis.tgz /tmp/xdebug.tgz \
|
||||
&& apt-get clean \
|
||||
&& apt-get autoclean
|
||||
|
||||
|
||||
BIN
php8.3/rdkafka-6.0.5.tgz
Normal file
BIN
php8.3/rdkafka-6.0.5.tgz
Normal file
Binary file not shown.
BIN
php8.3/redis-6.0.2.tgz
Normal file
BIN
php8.3/redis-6.0.2.tgz
Normal file
Binary file not shown.
BIN
php8.3/xdebug-3.4.3.tgz
Normal file
BIN
php8.3/xdebug-3.4.3.tgz
Normal file
Binary file not shown.
Reference in New Issue
Block a user