trungdv/base-laravel
Composer 安装命令:
composer require trungdv/base-laravel
包简介
Base Laravel Package - Quick Docker environment setup for Laravel development
README 文档
README
A comprehensive Laravel package for quickly initializing a base Laravel development environment with Docker setup, providing utilities for file management, template generation, and consistent API responses.
Features
- 🐳 Docker Environment: Complete Docker setup with Nginx, MySQL, and Laravel
- ⚡ Quick Setup: One command to initialize your development environment
- 🔧 Configurable: Customizable PHP and MySQL versions
- 📁 Auto-generated: Automatically creates necessary Docker files and configurations
- 🚀 Laravel Ready: Pre-configured for Laravel development
- 🛠️ Helper Utilities: File and directory management tools
- 📝 Template System: Stub-based file generation
- 🎯 Response Resource: Consistent API response formatting
- 🔗 Facade Support: Easy-to-use facade interface
- 📊 Service Container: Full Laravel integration
Requirements
- PHP >= 8.1
- Laravel >= 9.0
- Docker & Docker Compose
- Composer
Installation
1. Install via Composer
composer require trungdv/base-laravel
2. Publish Configuration
php artisan vendor:publish --provider="TrungDV\BaseLaravel\Providers\InitBaseProvider" --tag="config"
3. Configure Environment
Update your .env file with database configuration:
DB_CONNECTION=mysql DB_HOST=mysql DB_PORT=3306 DB_DATABASE=your_database_name DB_USERNAME=root DB_PASSWORD=your_password DB_TIME_ZONE=UTC
Usage
Initialize Base Environment
Run the following command to create your Docker environment:
php artisan make:base
This command will create:
docker-compose.yml- Docker Compose configurationdocker/directory with:Dockerfile- PHP-FPM container configurationhttp-nginx.conf- Nginx configurationphp.ini- PHP configurationinitdb/- Database initialization scriptsmysql/- MySQL logs directory
Start Development Environment
After running make:base, build and run your Docker environment:
docker-compose up -d --build
Your Laravel application will be available at:
- HTTP: http://localhost:9005
- HTTPS: https://localhost:443
Stop Development Environment
docker-compose down
Configuration
The package configuration is located in config/base.php:
return [ /* |-------------------------------------------------------------------------- | Default init base directory | */ 'project_name' => 'base_laravel', 'php_version' => '8.3', 'mysql_version' => '8.0', 'path' => 'app/Repositories', 'service_path' => 'app/Services', /* * Default repository namespace */ 'namespace' => 'App\Repositories', 'service_namespace' => 'App\Services', 'naming' => 'singular', // plural | singular 'response' => [ 'headers' => [ 'Content-Type' => 'application/json,charset=UTF-8', 'Access-Control-Allow-Credentials' => 'TRUE', 'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, DELETE, PUT, PATCH', 'Access-Control-Allow-Headers' => 'x-requested-with', 'Access-Control-Max-Age' => '864,000', ], ], ];
Customizing Versions
You can customize PHP and MySQL versions by updating the config:
// config/base.php 'php_version' => '8.2', // Change PHP version 'mysql_version' => '8.0', // Change MySQL version 'project_name' => 'my_project', // Change project name
Docker Services
Laravel Application
- Container:
{project_name}_laravel - Image: Custom PHP-FPM image (
trungdvfabbi/php-pecl:php{PHP_VERSION}) - Port: 9000 (internal)
- Volumes: Project files, PHP configuration
Nginx Web Server
- Container:
http-nginx - Image: nginx:1.23-alpine
- Ports: 9005 (HTTP), 443 (HTTPS)
- Configuration: Custom nginx config for Laravel
MySQL Database
- Container:
{project_name}_db - Image: mysql:8.0
- Port: 33061 (external)
- Volumes: Database data, logs, initialization scripts
Template System
The package uses a stub-based template system for generating files:
Available Templates
docker-compose.stub- Docker Compose configurationDockerfile.stub- PHP-FPM Dockerfilehttp-nginx.conf.stub- Nginx configurationphp.ini.stub- PHP configuration
Troubleshooting
Common Issues
-
Port Already in Use
- Change ports in
docker-compose.ymlif 9005 or 33061 are already in use
- Change ports in
-
Permission Issues
- Ensure Docker has proper permissions to access your project directory
- Check file ownership:
ls -la
-
Database Connection Issues
- Verify your
.envdatabase configuration matches the Docker setup - Check if MySQL container is running:
docker-compose ps
- Verify your
-
Container Won't Start
- Check Docker logs:
docker-compose logs [service_name] - Verify Docker is running:
docker --version
- Check Docker logs:
-
Template Not Found
- Ensure template files exist in
src/Stubs/directory - Check file permissions and naming convention
- Ensure template files exist in
Debugging
# View all container logs docker-compose logs # View specific service logs docker-compose logs laravel docker-compose logs mysql docker-compose logs http-nginx # Access container shell docker-compose exec laravel bash docker-compose exec mysql bash # Check container status docker-compose ps # Restart specific service docker-compose restart laravel
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This package is open-sourced software licensed under the MIT license.
Support
If you encounter any issues or have questions:
- 📧 Email: trungdv@fabbi.io
- 🐛 Issues: GitHub Issues
- 📖 Documentation: Package Documentation
Changelog
v1.0.0 - 2024-01-15
- ✅ Initial release
- ✅ Docker environment setup with Nginx, MySQL, and Laravel
- ✅ Configuration management system
- ✅ Response resource for consistent API responses
- ✅ Helper utilities for file and directory management
- ✅ Template system for file generation
- ✅ Facade support for easy usage
- ✅ Service Container integration
- ✅ Artisan command for environment initialization
- ✅ Comprehensive testing setup
- ✅ Complete documentation and examples
trungdv/base-laravel 适用场景与选型建议
trungdv/base-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mysql」 「development」 「base」 「laravel」 「environment」 「nginx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 trungdv/base-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 trungdv/base-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 trungdv/base-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
yii2 simialbi base
Encode integer IDs using a preset or customized symbol set
Debugging a problem and need to login as one of your customers? This allows you to authenticate as any of your customers.
Library with classes to help you do batch.
GHT D-Tools Bundle
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-22