Skip to content

mrtolouei/laravel-dockerized

Repository files navigation

🚀 Laravel Dockerized Project

A complete Laravel project with Docker configuration for easy development and quick deployment

Laravel Docker PHP PostgreSQL MySQL Redis

✨ Project Features

  • ✅ 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

🛠 Prerequisites

🚀 Project Setup

  1. Clone the project:
    git clone git@github.com:mrtolouei/laravel-dockerized.git
    cd laravel-dockerized
  2. Copy env file:
    cp .env.example .env
  3. Build and run containers:
    docker compose up -d --build
  4. Install dependencies (if not done automatically):
    docker exec -it laravel_php composer install --ignore-platform-reqs
  5. Generate application key:
    docker exec -it laravel_php php artisan key:generate
  6. Run migrations:
    docker exec -it laravel_php php artisan migrate
  7. Project is ready!:

🏗 Docker Structure

  • 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

⚙ Environment Configuration

Database Selection

You can choose between PostgreSQL or MySQL by:

  1. Uncommenting your preferred database service in docker-compose.yml
  2. Commenting out the other database service
  3. 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

🔄 Switching Between Databases

  1. 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
  2. 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.

About

A complete Laravel project with Docker configuration for easy development and quick deployment

Topics

Resources

Stars

Watchers

Forks