Skip to content

🐳 Docker image Nginx PHP-FPM container created to run Laravel or any php based applications, with extensions for Redis, Memcached, MySQL, Postgres, Events, Redis, Kafka, Laravel Schedule, Cron job and custom default configuration.

License

Notifications You must be signed in to change notification settings

jkaninda/nginx-php-fpm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐳 Docker Image: Nginx PHP-FPM

A ready-to-use container designed for running PHP-based applications, including Laravel microservices. This Docker image combines Nginx and PHP-FPM, offering a robust foundation for your projects with built-in support for essential extensions and configurations.

Build Tests Docker Image Size (latest by date) Docker Pulls

Features

  • PHP Application Support: Optimized to run Laravel or any PHP-based applications.
  • Integrated Extensions:
    • Database: MySQL and PostgreSQL.
    • Caching: Redis and Memcached.
    • Messaging: Kafka for event-driven architecture.
    • Task Scheduling: Laravel Scheduler and Cron jobs support.
  • Custom Configuration: Pre-configured with sensible defaults, allowing seamless customization.
  • Event Handling: Support for advanced event-driven processes.
  • Optimized for Microservices: Built with modern PHP microservices in mind.

This image is ideal for developers looking for a streamlined, high-performance solution to deploy PHP applications with essential tools already integrated.


Links

Supported PHP Versions

  • 8.4
  • 8.3
  • 8.2
  • 8.1
  • 8.0
  • 7.4
  • 7.2

Specifications

This Docker image comes pre-installed with the following:

  • PHP Extensions:

    • Composer
    • OpenSSL
    • XML
    • PDO
    • Rdkafka
    • Redis
    • Mbstring
    • PCNTL
    • ZIP
    • GD
    • BCMath
    • Memcached
  • Additional Features:

    • Laravel Cron Jobs & Scheduler
    • Supervisord
    • Node.js & NPM

Basic Usage with Docker Compose

Example docker-compose.yml

services:
  app:
    image: jkaninda/nginx-php-fpm:8.3
    container_name: app
    restart: unless-stopped
    user: www-data # Optional for production
    volumes:
      # Project root
      - ./src:/var/www/html
    ports:
      - "80:80"
    networks:
      - default

Commands

Start the service:

docker compose up -d

Create a new Laravel project:

docker compose exec app composer create-project --prefer-dist laravel/laravel .

Generate application key:

docker compose exec app php artisan key:generate

Create a storage symlink:

docker compose exec app php artisan storage:link

Fix storage and cache permissions:

docker compose exec app chmod -R 777 storage bootstrap/cache

Run Laravel migrations:

docker compose exec app php artisan migrate

Access the container shell:

docker exec -it app bash

Advanced Nginx PHP-FPM Setup

Extended docker-compose.yml Example

version: '3'
services:
  app:
    image: jkaninda/nginx-php-fpm
    container_name: app
    restart: unless-stopped
    ports:
      - "80:80"
    volumes:
      # Project root
      - ./:/var/www/html
      - ~/.ssh:/root/.ssh # Use private CVS if needed
      # Optional custom PHP config
      # - ./php.ini:/usr/local/etc/php/conf.d/php.ini
    environment:
      - APP_ENV=development # or production
      - LARAVEL_PROCS_NUMBER=2 # Optional: Queue worker processes
      # - CLIENT_MAX_BODY_SIZE=20M # Optional
      # - DOMAIN=example.com # Optional
      - DOCUMENT_ROOT=/var/www/html # Optional

Default Web Root

/var/www/html

Custom Build Example

Dockerfile

FROM jkaninda/nginx-php-fpm:8.3
# Copy Laravel project files
COPY . /var/www/html
# Storage Volume
VOLUME /var/www/html/storage

WORKDIR /var/www/html

# Fix permissions
RUN chown -R www-data:www-data /var/www/html

USER www-data

Custom Nginx Configuration

To enable custom Nginx configurations, use the following files:

  • /var/www/html/conf/nginx/nginx.conf
  • /var/www/html/conf/nginx/nginx-site.conf

Supervisord Integration

Supervisord can be used to manage tasks or processes within the container.

Example Configuration for Kafka Consumer

[program:kafkaconsume-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan kafka:consumer
autostart=true
autorestart=true
numprocs=1
user=www-data
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/kafka.log

Fixing Storage Permissions

If you encounter storage permission issues, run the following commands:

docker compose exec php-fpm /bin/bash

Then inside the container:

chown -R www-data:www-data /var/www/html/
chmod -R 775 /var/www/html/storage

Star the Project

If you find this project useful, please give it a ⭐️ on GitHub to show your support! 😊

About

🐳 Docker image Nginx PHP-FPM container created to run Laravel or any php based applications, with extensions for Redis, Memcached, MySQL, Postgres, Events, Redis, Kafka, Laravel Schedule, Cron job and custom default configuration.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published