m1n64/yii2-docker-app-basic
最新稳定版本:1.0.0
Composer 安装命令:
composer create-project m1n64/yii2-docker-app-basic
包简介
Yii 2 Basic Project Template with Docker
README 文档
README
This is a Docker-based template for Yii 2, built with:
- PHP 8.4 (FPM on Alpine)
- PostgreSQL 16
- Redis
- Node.js 22 + NPM
- Supervisor for Queue & Scheduler
- Makefile for easy commands (like Laravel Sail)
- Nginx
- Composer
- XDebug in Dev Mode
🛠 Setup Instructions
1️⃣ Clone the Repository
composer create-project m1n64/yii2-docker-app-basic yii2-app
cd yii2-app
2️⃣ Copy .env and Update Configuration
cp .env.example .env
- Open
.envfile and change it:
DB_DATABASE=<your-db> # Change DB name
-
Change the container name prefix:
Inside
docker-compose.yml, renamey2-to your project name:
services: app: container_name: myproject-app nginx: container_name: myproject-nginx postgres: container_name: myproject-postgres redis: container_name: myproject-redis
-
Change the Docker network
In
docker-compose.yml:
networks: myproject-network:
🚀 Start Containers
🔹 Using Docker
docker-compose up -d
🔹 Using Makefile
make up # For development make prod # For production
📦 Install Dependencies
🛠 Install PHP Dependencies
Run inside the container:
docker-compose exec -u www-data app composer install
Or using Makefile:
make composer install
🎸 Install Node.js & NPM Dependencies
make npm install
make npm run dev # Run Vite for development
📜 Run Migrations
make yii migrate
💻 Available Commands
🛠 Running Laravel Commands
| Action | Docker Command | Makefile Shortcut |
|---|---|---|
Run php yii |
docker-compose exec -u www-data app php yii <cmd> |
make yii <cmd> |
Run composer |
docker-compose exec -u www-data app composer <cmd> |
make composer <cmd> |
Run npm |
docker-compose exec -u www-data app npm <cmd> |
make npm <cmd> |
| Open Bash | docker-compose exec -u www-data app bash |
make bash |
| View Logs | docker-compose logs -f app |
make logs app |
| Open PostgreSQL CLI | docker-compose exec -e PGPASSWORD=<pass> postgres psql -U <user> -d <db> |
make psql |
| Open Redis CLI | docker-compose exec redis redis-cli |
make redis |
| Run Tests | docker-compose exec -u www-data app php yii test |
make test |
🛑 Managing Containers
🔄 Restart & Stop
| Action | Docker Command | Makefile Shortcut |
|---|---|---|
| Restart all | docker-compose restart |
make restart |
| Restart one | docker-compose restart <service> |
make restart-container CONTAINER=<name> |
| Stop all | docker-compose stop |
make stop |
| Stop one | docker-compose stop <service> |
make stop-container CONTAINER=<name> |
| Start all | docker-compose up -d |
make up |
| Remove all | docker-compose down -v |
make down |
For list of all makefile commands, run make help.
💡 PHPStorm Setup
PHP Interpreter
XDebug
🧪 Run Tests
make test
📜 Additional Notes
- This setup supports Queues & Scheduler via Supervisor.
- PostgreSQL, Redis & Supervisor are configured out of the box.
- Uses Node.js 22 for Vite & frontend dependencies if you need.
- All Docker volumes persist data between container restarts.
🔥 Now your Yii 2 project is fully containerized!
Use Makefile commands just enjoy seamless Docker development! 🚀
🤖 Authors
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-06-01