A complete Laravel project with Docker configuration for easy development and quick deployment
- ✅ Complete Docker and docker-compose configuration
- ✅ PHP 8.3 with all required Laravel extensions
- ✅ Optimized Nginx server for Laravel
- ✅ Database options: PostgreSQL 16 or MySQL 8.0
- ✅ Redis for cache and queues
- ✅ Auto-configured Xdebug for debugging
- ✅ Cron job management with Supercronic
- ✅ Horizon support for queue management
- ✅ Consistent and reproducible development environment
- Clone the project:
git clone git@github.com:mrtolouei/laravel-dockerized.git cd laravel-dockerized
- Copy env file:
cp .env.example .env
- Build and run containers:
docker compose up -d --build
- Install dependencies (if not done automatically):
docker exec -it laravel_php composer install --ignore-platform-reqs
- Generate application key:
docker exec -it laravel_php php artisan key:generate
- Run migrations:
docker exec -it laravel_php php artisan migrate
- Project is ready!:
- Open in browser: http://localhost:8000
- nginx: Web server with optimized configuration for Laravel
- php: PHP 8.3 service with all required extensions
- postgres: PostgreSQL 16 database (default)
- mysql: MySQL 8.0 database (commented by default)
- redis: Redis service for cache and queues
You can choose between PostgreSQL or MySQL by:
- Uncommenting your preferred database service in
docker-compose.yml
- Commenting out the other database service
- Updating the
.env
file with appropriate DB configuration
Default values in .env
(PostgreSQL):
# For PostgreSQL use:
DB_CONNECTION=pgsql
DB_HOST=postgres
DB_PORT=5432
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=secret
# For MySQL use:
# DB_CONNECTION=mysql
# DB_HOST=mysql
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=laravel
# DB_PASSWORD=secret
- To switch to MySQL:
- Uncomment the MySQL service in
docker-compose.yml
- Comment the PostgreSQL service
- Update
.env
with MySQL credentials - Rebuild containers:
docker-compose up -d --build
- Uncomment the MySQL service in
- To switch back to PostgreSQL:
- Uncomment the PostgreSQL service
- Comment the MySQL service
- Update
.env
with PostgreSQL credentials - Rebuild containers:
docker-compose up -d --build
Note: Make sure to backup your data before switching databases as each uses different volumes.