Skip to content

Atyantik/docker-laravel-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Atyantik's Laravel PHP Docker Image 🌟

Docker Hub

This repository provides a custom PHP 8.4 Docker image based on the Bullseye distribution, optimized for running Laravel applications. It includes pre-installed PHP extensions, tools, and multi-architecture support for AMD64 and ARM64. πŸš€


✨ Features: What This Dockerfile Provides

This Dockerfile is tailored for Laravel applications and includes the following features:

  1. PHP 8.4 with FPM (FastCGI Process Manager).
  2. βœ… Pre-installed PHP Extensions:
    • Essential extensions required by most Laravel applications.
    • See the Extension Table below for a full list. 🧩
  3. βœ… Pre-installed Tools:
    • Composer (globally available for dependency management).
    • MongoDB Tools (e.g., mongodump) for database backups and operations.
  4. βœ… Xdebug:
    • Included but disabled by default for production readiness.
    • XDebug 3.4.0beta1 is used for compatibility with php 8.4
  5. βœ… Multi-Architecture Builds:
    • Supports both AMD64 (x86_64) and ARM64 (aarch64) architectures.

🧩 PHP Extensions

Here's a detailed list of pre-installed PHP extensions:

Extension Description Status
pdo_mysql MySQL database support βœ…
pdo_pgsql PostgreSQL database support βœ…
pdo_sqlite SQLite lightweight database support βœ…
mbstring Multibyte string handling for UTF-8 support βœ…
intl Internationalization and localization features βœ…
gd Image processing (JPEG, PNG) βœ…
zip Support for ZIP compression βœ…
opcache Performance optimization through script caching βœ…
soap SOAP-based web services βœ…
redis Redis for caching and sessions βœ…
memcached Memcached for caching and sessions βœ…
mongodb MongoDB database support βœ…
gmp Arbitrary precision arithmetic βœ…
exif Metadata handling for images βœ…

πŸ›  Pre-installed Tools

  1. Composer:

    • Installed globally for dependency management.
    • Optimized to use only HTTPS for Packagist repositories.
  2. MongoDB Tools:

    • Includes mongodump for backup operations and other utilities.

πŸš€ How to Use

This Docker image is available on Docker Hub. You can pull it directly or use it as a base image in your own Dockerfile:

FROM atyantik/laravel-php:8.4-bullseye

Example: Running a Laravel Application

  1. Build your Laravel application image using this base image:
    FROM atyantik/laravel-php:8.4-bullseye
    
    COPY . /var/www/html
    WORKDIR /var/www/html
    
    RUN composer install --no-dev --optimize-autoloader
  2. Start the container:
    docker run -p 8000:9000 my-laravel-app

πŸ›  Compilation Steps

Follow these steps to build the image yourself:

  1. Clone the Repository:

    git clone https://github.com/atyantik/laravel-php-docker.git
    cd laravel-php-docker
  2. Enable Buildx for Multi-Architecture Builds:

  3. Build AMD64 Image:

    docker buildx build --platform="linux/amd64" -t atyantik/laravel-php:8.4-bullseye-amd64 .
  4. Build ARM64 Image:

    docker buildx build --platform="linux/arm64" -t atyantik/laravel-php:8.4-bullseye-arm64 .
  5. Push Images to Docker Hub:

    docker push atyantik/laravel-php:8.4-bullseye-amd64
    docker push atyantik/laravel-php:8.4-bullseye-arm64
  6. Create and Push a Manifest for Multi-Architecture:

    docker manifest create atyantik/laravel-php:8.4-bullseye \
      atyantik/laravel-php:8.4-bullseye-amd64 \
      atyantik/laravel-php:8.4-bullseye-arm64
    docker manifest push atyantik/laravel-php:8.4-bullseye

πŸ’» Visit us at: atyantik.com

πŸ“š Examples and Docker Configurations

This repository includes two types of example configurations to help you get started:

1. General PHP Application Setup

Located in example/general/, this is a simple setup for any PHP application:

services:
  app:
    image: atyantik/laravel-php:8.4-bullseye
    volumes:
      - ./public:/var/www/html
      - ./php/php.ini:/usr/local/etc/php/php.ini

  webserver:
    image: nginx:latest
    volumes:
      - ./public:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "8080:80"
    depends_on:
      - app

This configuration provides:

  • PHP-FPM service using our custom image
  • Nginx web server
  • Basic volume mounting for code and configuration
  • Simple networking between services

2. Laravel-Specific Setup

Located in example/laravel/, this is a comprehensive setup for Laravel applications with two environments:

Local Development (compose.yml)

A complete development environment with:

  • PostgreSQL database
  • Redis for caching and queues
  • Mailpit for email testing
  • pgAdmin for database management
  • Memcached for caching
  • MinIO for S3-compatible storage
  • Supervisor for queue workers
  • Nginx web server
  • Vite support for frontend development

Key features:

  • Hot-reloading for development
  • Persistent data storage
  • Development tools (Mailpit, pgAdmin)
  • Local storage for files and databases

Staging Environment (compose.staging.yml)

A production-like environment with:

  • Optimized PHP configuration
  • Secure Redis setup
  • Persistent volumes
  • SSL support
  • Production-ready Nginx configuration
  • Bootstrapper for initial setup

Key differences from development:

  • No development tools
  • Secure configurations
  • Production-ready settings
  • Volume-based storage
  • SSL support

How to Use These Examples

  1. For General PHP Applications:

    cd example/general
    docker-compose up -d

    Access your application at http://localhost:8080

  2. For Laravel Applications: To integrate these Docker configurations into your existing Laravel project:

    1. Copy the following files from example/laravel/ to your project root:

      • compose.yml (for development)
      • compose.staging.yml (for staging)
      • docker/ directory with all its contents
    2. Update your Laravel configuration files:

      • In bootstrap/app.php, ensure allowing trustedProxies
      • In vite.config.js, update the server.hmr
      • In your project's .env file, add these variables:
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=local_laravel
DB_PASSWORD=local@laravel

REDIS_CLIENT=phpredis
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=log
MAIL_SCHEME=null
MAIL_HOST=mail
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=minioadmin
AWS_SECRET_ACCESS_KEY=minioadmin
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=laravel-bucket
AWS_USE_PATH_STYLE_ENDPOINT=true
AWS_ENDPOINT=http://s3:9000

MEMCACHED_HOST=memcached
CACHE_STORE=memcached
QUEUE_CONNECTION=redis
FILESYSTEM_DISK=s3
APP_URL=https://laravel.localhost
COMPOSE_BAKE=true
  1. Start the services:
    # Development
    docker compose up -d
    
    # Staging
    docker compose -f compose.staging.yml up -d

Best Practices

  1. Development:

    • Use the development configuration for local development
    • Enable Xdebug when needed
    • Use Mailpit for email testing
    • Utilize pgAdmin for database management
  2. Staging:

    • Use the staging configuration as a base
    • Implement proper SSL certificates
    • Set secure passwords for all services
    • Use persistent volumes for data
    • Configure proper backup strategies
    • Whenever possible use proper staging configuration not the provided docker-compose.yml
    • The provided configurations is to get staging server quick up and running on single server instance.
  3. Security:

    • Never commit sensitive environment variables
    • Use strong passwords in production
    • Implement proper SSL/TLS
    • Regularly update container images

🌐 Links


🀝 About Atyantik Technologies

Atyantik Logo

At Atyantik Technologies, we specialize in building world-class software solutions with a focus on innovation, scalability, and efficiency. We believe in delivering value through cutting-edge technologies and industry best practices.

About

PHP Container for maintaining Laravel applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published