Laravel + MySQL
PHP Laravel framework with MySQL and Redis.
[i]Overview
Laravel is an elegant PHP web framework that follows the Model-View-Controller (MVC) architectural pattern, created by Taylor Otwell in 2011. Built on the Symfony framework components, Laravel emphasizes developer productivity through expressive syntax, built-in features like Eloquent ORM, Blade templating engine, and Artisan command-line tool. It has become one of the most popular PHP frameworks due to its clean architecture, comprehensive documentation, and vibrant ecosystem of packages through Composer and Laravel-specific tools like Nova and Forge.
This stack combines Laravel's rapid development capabilities with MySQL's proven relational database performance and Redis's lightning-fast caching and session storage. NGINX serves as the high-performance web server handling static assets and reverse proxying to PHP-FPM, while MySQL manages persistent data with ACID compliance and complex relationships that Laravel's Eloquent ORM excels at handling. Redis accelerates the application by caching database queries, storing user sessions, and managing Laravel's queue system for background job processing.
This configuration targets web development teams building content management systems, e-commerce platforms, SaaS applications, and API backends that require robust data relationships, user authentication, and high-performance caching. Laravel developers working on applications with complex business logic, multi-user systems, or projects requiring rapid prototyping will benefit from this stack's balance of development speed and production reliability.
[*]Key Features
- [+]Laravel Eloquent ORM with MySQL for complex database relationships and migrations
- [+]Redis-powered session storage and cache driver for sub-millisecond response times
- [+]NGINX FastCGI integration with PHP-FPM for optimal Laravel application performance
- [+]Laravel Queue system backed by Redis for asynchronous job processing
- [+]MySQL InnoDB storage engine with full ACID compliance for data integrity
- [+]Laravel Artisan command-line tool integration for migrations and maintenance
- [+]Redis Pub/Sub messaging for real-time Laravel broadcasting and WebSocket support
- [+]NGINX static asset serving with Laravel Mix optimization support
[#]Common Use Cases
- [1]E-commerce platforms requiring complex product catalogs, inventory management, and order processing
- [2]Content management systems with hierarchical data structures and media libraries
- [3]SaaS applications needing multi-tenant architecture with user authentication and authorization
- [4]RESTful API backends for mobile applications with token-based authentication
- [5]Educational platforms with course management, user progress tracking, and payment integration
- [6]Real-time applications using Laravel Echo with Redis for chat systems or live updates
- [7]Enterprise web applications requiring role-based permissions and audit logging
[!]Prerequisites
- [!]Minimum 2GB RAM (1GB for MySQL, 512MB for Redis, 512MB for Laravel/NGINX)
- [!]PHP and Laravel framework knowledge including Eloquent ORM and Blade templating
- [!]MySQL database design experience with understanding of indexes and relationships
- [!]Port 80 available for web traffic and familiarity with NGINX configuration
- [!]Composer dependency manager knowledge for Laravel package management
- [!]Basic understanding of Redis data structures for caching and session implementation
[!]
WARNING: For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
[$]docker-compose.yml
[docker-compose.yml]
1services: 2 app: 3 build: .4 container_name: laravel5 volumes: 6 - .:/var/www/html7 networks: 8 - laravel910 nginx: 11 image: nginx:alpine12 container_name: nginx13 volumes: 14 - .:/var/www/html:ro15 - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro16 ports: 17 - "80:80"18 depends_on: 19 - app20 networks: 21 - laravel2223 mysql: 24 image: mysql:8.025 container_name: mysql26 environment: 27 MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}28 MYSQL_DATABASE: ${MYSQL_DATABASE}29 MYSQL_USER: ${MYSQL_USER}30 MYSQL_PASSWORD: ${MYSQL_PASSWORD}31 volumes: 32 - mysql_data:/var/lib/mysql33 networks: 34 - laravel3536 redis: 37 image: redis:alpine38 container_name: redis39 networks: 40 - laravel4142volumes: 43 mysql_data: 4445networks: 46 laravel: 47 driver: bridge[$].env Template
[.env]
1MYSQL_ROOT_PASSWORD=rootpassword2MYSQL_DATABASE=laravel3MYSQL_USER=laravel4MYSQL_PASSWORD=changeme[i]Usage Notes
- [1]Docs: https://laravel.com/docs
- [2]Create Dockerfile with PHP-FPM + composer
- [3]Run migrations: docker compose exec app php artisan migrate
- [4]Access at http://localhost
- [5]Generate app key: docker compose exec app php artisan key:generate
- [6]Queue worker: docker compose exec app php artisan queue:work
Individual Services(4 services)
Copy individual services to mix and match with your existing compose files.
app
app:
build: .
container_name: laravel
volumes:
- .:/var/www/html
networks:
- laravel
nginx
nginx:
image: nginx:alpine
container_name: nginx
volumes:
- .:/var/www/html:ro
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
ports:
- "80:80"
depends_on:
- app
networks:
- laravel
mysql
mysql:
image: mysql:8.0
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- mysql_data:/var/lib/mysql
networks:
- laravel
redis
redis:
image: redis:alpine
container_name: redis
networks:
- laravel
[>]Quick Start
[terminal]
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 app:5 build: .6 container_name: laravel7 volumes:8 - .:/var/www/html9 networks:10 - laravel1112 nginx:13 image: nginx:alpine14 container_name: nginx15 volumes:16 - .:/var/www/html:ro17 - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro18 ports:19 - "80:80"20 depends_on:21 - app22 networks:23 - laravel2425 mysql:26 image: mysql:8.027 container_name: mysql28 environment:29 MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}30 MYSQL_DATABASE: ${MYSQL_DATABASE}31 MYSQL_USER: ${MYSQL_USER}32 MYSQL_PASSWORD: ${MYSQL_PASSWORD}33 volumes:34 - mysql_data:/var/lib/mysql35 networks:36 - laravel3738 redis:39 image: redis:alpine40 container_name: redis41 networks:42 - laravel4344volumes:45 mysql_data:4647networks:48 laravel:49 driver: bridge50EOF5152# 2. Create the .env file53cat > .env << 'EOF'54MYSQL_ROOT_PASSWORD=rootpassword55MYSQL_DATABASE=laravel56MYSQL_USER=laravel57MYSQL_PASSWORD=changeme58EOF5960# 3. Start the services61docker compose up -d6263# 4. View logs64docker compose logs -f[>]One-Liner
Run this command to download and set up the recipe in one step:
[terminal]
1curl -fsSL https://docker.recipes/api/recipes/laravel-mysql/run | bash[?]Troubleshooting
- [!]Laravel key not set error: Run 'docker compose exec app php artisan key:generate' to generate application encryption key
- [!]MySQL connection refused: Verify MYSQL_DATABASE, MYSQL_USER, and MYSQL_PASSWORD environment variables match Laravel's .env configuration
- [!]Redis connection timeout: Ensure Redis container is running and Laravel REDIS_HOST is set to 'redis' (container name)
- [!]NGINX 502 Bad Gateway: Check that PHP-FPM is running in the Laravel container and NGINX upstream configuration points to correct FastCGI socket
- [!]Laravel storage permissions error: Run 'docker compose exec app chown -R www-data:www-data storage bootstrap/cache' to fix file permissions
- [!]MySQL data persistence lost: Verify mysql_data volume is properly mounted and not being recreated between container restarts
Community Notes
Loading...
Loading notes...
## Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Shortcuts: C CopyF FavoriteD Download