This document covers development operations, deployment strategies, and environment management for the Laravel API SOLID project.
- PHP 8.2 or higher
- Composer 2.x
- Node.js 18+ and npm
- SQLite (default) or MySQL/PostgreSQL
- Git
-
Clone the repository
git clone <repository-url> cd laravel-api-solid
-
Install PHP dependencies
composer install
-
Install Node.js dependencies
npm install
-
Environment configuration
cp .env.example .env php artisan key:generate
-
Database setup
touch database/database.sqlite # For SQLite php artisan migrate php artisan db:seed -
Passport setup
php artisan passport:install
composer dev- Start development environment with concurrent processescomposer test- Run the test suitecomposer pint- Fix code style issues
npm run dev- Start Vite development servernpm run build- Build assets for production
php artisan serve- Start development serverphp artisan queue:work- Process queue jobsphp artisan pail- Real-time log monitoring
-
Start development environment
composer dev
This starts:
- Laravel development server (port 8000)
- Queue worker
- Log monitoring (Pail)
- Vite development server
-
Code style and quality
composer pint # Fix code style composer test # Run tests
This project includes a comprehensive Docker setup with separate development and production environments, designed for professional deployment with managed cloud services.
- Development Environment (
compose.dev.yaml) - Full local development stack - Production Environment (
compose.prod.yaml) - Optimized for deployment with external managed services - Multi-stage Dockerfile - Optimized builds for both environments
- Managed Database Strategy - External PostgreSQL for production scalability
| Service | Container | Port | Purpose |
|---|---|---|---|
| app | laravel-app-dev | 9000 | PHP-FPM application server |
| nginx | laravel-nginx-dev | 8000 | Web server and reverse proxy |
| postgres | laravel-postgres-dev | 5432 | PostgreSQL database |
| workspace | laravel-workspace-dev | - | Development tools and CLI |
| redis | laravel-redis-dev | 6379 | Cache and session storage |
| mailhog | laravel-mailhog-dev | 1025/8025 | Email testing |
# Initial setup
make setup # Complete setup with dependencies
make dev # Start development environment
make shell # Access workspace shell
# Development workflow
make artisan cmd="migrate" # Run Laravel commands
make npm-dev # Start Vite dev server
make test # Run tests- Live Code Editing: Volume mounts for real-time development
- Xdebug: Debugging support for PHP
- Node.js & npm: Frontend development tools
- PostgreSQL: Primary database with test database
- SQLite: Alternative lightweight database
- MailHog: Email testing at http://localhost:8025
- Application: Available at http://localhost:8000
| Service | Container | Purpose |
|---|---|---|
| app | laravel-app-prod | Optimized PHP-FPM server |
| nginx | laravel-nginx-prod | Production web server |
| queue | laravel-queue-prod | Background job processing |
| scheduler | laravel-scheduler-prod | Laravel cron jobs |
- Multi-stage Build: Optimized production images
- External Database: Connects to managed PostgreSQL (RDS, etc.)
- Health Checks: Container health monitoring
- Security: Non-root users, minimal attack surface
- Performance: OPcache, optimized configurations
- Scalability: Horizontal scaling ready
# Configure environment
cp .env.prod .env
# Edit .env with your production values
# Deploy
./scripts/docker-prod.sh deploy
# Management commands
./scripts/docker-prod.sh status
./scripts/docker-prod.sh scale queue 3
./scripts/docker-prod.sh logs app 100The production environment deliberately excludes a PostgreSQL container and connects to external managed database services (AWS RDS, Google Cloud SQL, Azure Database).
Benefits:
- Disaster Recovery: Automated backups, cross-region replication, point-in-time recovery
- Automatic Backups: Continuous transaction logs, daily snapshots, backup encryption
- Vertical Scaling: CPU/memory scaling without downtime, read replicas, performance insights
- Security & Compliance: Encryption at rest/transit, VPC isolation, SOC/PCI/HIPAA compliance
- Operational Benefits: Managed maintenance, 24/7 support, 99.99% uptime SLA
# Database (Managed PostgreSQL)
DB_HOST=your-rds-endpoint.amazonaws.com
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_secure_password
DB_SSLMODE=require
# Cache (Managed Redis)
REDIS_HOST=your-redis-endpoint.amazonaws.com
REDIS_PASSWORD=your_redis_password
REDIS_TLS=true
# Storage (AWS S3)
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_BUCKET=your_s3_bucketdocker/
├── common/
│ └── php-fpm.Dockerfile # Multi-stage PHP-FPM container
├── dev/
│ ├── nginx.conf # Development web server config
│ ├── php.ini # Development PHP settings
│ ├── php-fpm.conf # Development PHP-FPM pool
│ ├── xdebug.ini # Xdebug configuration
│ ├── workspace.Dockerfile # Development workspace
│ └── postgres-init.sql # PostgreSQL initialization
└── prod/
├── nginx.conf # Production web server config
├── php.ini # Production PHP settings
└── php-fpm.conf # Production PHP-FPM pool
The Makefile provides 30+ automation commands:
# Development
make dev # Start development environment
make shell # Access workspace shell
make artisan cmd="migrate" # Run artisan commands
make composer-install # Install PHP dependencies
make npm-install # Install Node dependencies
make test # Run tests
# Production
make prod-build # Build production environment
make setup-prod # Initial production setup
# Database
make migrate # Run migrations
make db-shell # Access PostgreSQL shell
make db-dump # Create database dump
# Monitoring
make status # Show container status
make logs # Show logs- Non-root container execution
- Security headers and rate limiting
- Secrets management via environment variables
- Minimal production images (no dev tools)
- SSL/TLS ready configuration
- Network isolation and proper firewall rules
- Multi-stage builds for minimal image size
- OPcache enabled in production
- Gzip compression and HTTP/2 ready
- Asset compilation and optimization
- Redis caching for sessions and application cache
- Database connection pooling ready
- Health check endpoints (/health, /ping, /status)
- Structured JSON logging for production
- Container resource monitoring
- Application performance monitoring ready
- Log aggregation and alerting ready
📖 Complete Docker Documentation - Detailed setup and usage guide
- SQLite (default for development)
- MySQL (recommended for production)
- PostgreSQL (alternative for production)
# Create new migration
php artisan make:migration create_posts_table
# Run migrations
php artisan migrate
# Rollback migrations
php artisan migrate:rollback
# Fresh migration with seeding
php artisan migrate:fresh --seed# Create seeder
php artisan make:seeder PostSeeder
# Run specific seeder
php artisan db:seed --class=PostSeeder
# Run all seeders
php artisan db:seed# Application
APP_KEY=base64:...
APP_ENV=production
APP_DEBUG=false
# Database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_api
DB_USERNAME=root
DB_PASSWORD=
# Passport
PASSPORT_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----..."
PASSPORT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----..."- Never commit
.envfiles - Use strong, unique APP_KEY
- Secure database credentials
- Configure HTTPS in production
- Regular security updates
-
Environment Setup
- Configure production
.env - Set
APP_ENV=production - Set
APP_DEBUG=false - Configure database credentials
- Set up SSL certificates
- Configure production
-
Application Deployment
# Install dependencies composer install --no-dev --optimize-autoloader # Build assets npm ci npm run build # Cache configuration php artisan config:cache php artisan route:cache php artisan view:cache # Run migrations php artisan migrate --force # Install Passport keys php artisan passport:keys
-
Server Configuration
- Configure web server (Nginx/Apache)
- Set up process manager (Supervisor)
- Configure queue workers
- Set up log rotation
-
Blue-Green Deployment
- Deploy to staging environment
- Run tests and validation
- Switch traffic to new version
- Keep old version as backup
-
Rolling Deployment
- Deploy to subset of servers
- Gradually roll out to all servers
- Monitor for issues during rollout
- Laravel Telescope: Development debugging
- Laravel Horizon: Queue monitoring
- Laravel Pulse: Application performance
# Real-time log monitoring
php artisan pail
# Log channels configuration in config/logging.php
# - single: Single file
# - daily: Daily rotation
# - slack: Slack notifications
# - stack: Multiple channels- Application Performance Monitoring (APM)
- Database query monitoring
- Cache hit/miss ratios
- Queue job processing times
name: Laravel CI/CD
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Install dependencies
run: composer install
- name: Run tests
run: php artisan test
- name: Code style check
run: ./vendor/bin/pint --test- Automated testing on pull requests
- Code quality checks (Pint, PHPStan)
- Security scanning (Composer audit)
- Automated deployment to staging
- Manual approval for production
# MySQL backup
mysqldump -u username -p database_name > backup.sql
# PostgreSQL backup
pg_dump -U username database_name > backup.sql
# Automated backup script
php artisan backup:run- Application files: Version controlled in Git
- Storage files: Regular backup to cloud storage
- Configuration files: Secure backup of
.envfiles
- Recovery Time Objective (RTO): < 1 hour
- Recovery Point Objective (RPO): < 15 minutes
- Backup testing: Monthly restore tests
- Documentation: Detailed recovery procedures
- Load balancers: Distribute traffic across multiple servers
- Database clustering: Master-slave replication
- Cache layers: Redis/Memcached clusters
- CDN: Static asset distribution
- Server resources: CPU, RAM, storage upgrades
- Database optimization: Query optimization, indexing
- Application optimization: Code profiling, caching
- Service decomposition: Split by domain boundaries
- API gateway: Centralized routing and authentication
- Service discovery: Dynamic service registration
- Data consistency: Event-driven architecture
-
Permission Issues
sudo chown -R www-data:www-data storage bootstrap/cache sudo chmod -R 775 storage bootstrap/cache
-
Cache Issues
php artisan cache:clear php artisan config:clear php artisan route:clear php artisan view:clear
-
Queue Issues
php artisan queue:restart php artisan queue:work --tries=3
- Laravel Telescope: Request/response debugging
- Laravel Debugbar: Development debugging
- Xdebug: Step-through debugging
- Laravel Pail: Real-time log monitoring