Skip to content

Production-ready Docker image for Laravel applications, featuring Nginx, PHP-FPM 8.3, and Supervisor. Optimized for AWS ECS/Fargate CloudWatch-compatible logging.

Notifications You must be signed in to change notification settings

aloilor/phpfpm-nginx-composer-laravel-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

PHP-FPM + Nginx + Composer + Laravel Docker Image

This Docker image provides a production-ready environment for running Laravel and Statamic applications. It combines Nginx, PHP-FPM 8.3, and Supervisor in a single container.

Image Components

  • Base Image: php:8.3-fpm-alpine (Alpine Linux-based PHP-FPM)
  • Web Server: Nginx
  • Process Manager: Supervisor
  • PHP Version: 8.3
  • Composer: Latest version

Key Features

1. PHP Extensions

The image includes essential PHP extensions:

  • bcmath
  • exif
  • gd
  • intl
  • mbstring
  • pdo_mysql
  • opcache

2. Application Setup

  • Uses Composer for dependency management
  • Optimizes autoloader for production
  • Pre-warms Statamic/Laravel caches
  • Sets up proper permissions for storage and cache directories

3. Process Management

Supervisor manages two main processes:

  • PHP-FPM (FastCGI Process Manager)
  • Nginx web server

4. Logging Strategy

The image implements a comprehensive logging strategy optimized for container environments:

Nginx Logging

  • Access logs are redirected to STDOUT
  • Error logs are redirected to STDERR
  • Log rotation is disabled for container-friendly logging

PHP-FPM Logging

  • Error logs are redirected to STDERR
  • Worker output is captured
  • Log level set to "notice"

PHP Error Handling

  • Error logging enabled
  • Display errors disabled (production-safe)
  • Errors logged to STDERR

This logging setup ensures:

  • All logs are properly captured in container environments
  • Compatibility with AWS CloudWatch

5. Health Checks

  • Built-in health check endpoint at /healthz
  • 90-second interval health checks
  • 3-second timeout

Configuration Files

Nginx Configuration

  • Listens on port 8080
  • Configured for Laravel/Statamic routing
  • Includes health check endpoint

Supervisor Configuration

  • Runs in foreground mode (PID 1)
  • Manages both Nginx and PHP-FPM processes
  • Configures proper logging for both services

Usage

Building the Image

docker build -t your-image-name .

Running the Container

docker run -p 8080:8080 your-image-name

Environment Variables

The application can be configured using standard Laravel environment variables.

Notes

  • The image is designed to run as a single container in production
  • All logs are properly forwarded to container logs
  • The setup is optimizedg for AWS ECS/Fargate logging into Cloudwatch through awslogs driver.

About

Production-ready Docker image for Laravel applications, featuring Nginx, PHP-FPM 8.3, and Supervisor. Optimized for AWS ECS/Fargate CloudWatch-compatible logging.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published