Files
php-docker-env/README.md
2025-06-09 16:46:27 +08:00

91 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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/` 目录