Skip to content

🐳 Docker PHP-FPM image created to run Laravel or any php based application, 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/laravel-php-fpm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

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

Repository files navigation

🐳 Docker Image: Laravel PHP-FPM

A ready-to-use container designed for running PHP-based applications, including Laravel microservices. This Docker image comes with 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

Logo

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

PHP Extensions

  • Composer
  • OpenSSL
  • XML
  • PDO (MySQL and PostgreSQL)
  • Rdkafka
  • Redis
  • Mbstring
  • PCNTL
  • ZIP
  • GD
  • BCMath
  • Memcached
  • Opcache

Additional Features

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

Getting Started

Simple Docker-Compose Example

services:
  php-fpm:
    image: jkaninda/laravel-php-fpm:latest
    container_name: php-fpm
    restart: unless-stopped
    user: www-data # For production
    volumes:
      - ./:/var/www/html
    networks:
      - default
  nginx-server:
     image: jkaninda/nginx-fpm:alpine
     container_name: nginx-server
     restart: unless-stopped
     ports:
      - 80:80
     volumes:
      - ./:/var/www/html
     environment:
       - DOCUMENT_ROOT=/var/www/html/public
       - CLIENT_MAX_BODY_SIZE=20M
       - PHP_FPM_HOST=php-fpm:9000 
     networks:
      - default

Basic Commands

  • Start Containers

    docker compose up -d
  • Create a Laravel Project

    docker compose exec php-fpm composer create-project --prefer-dist laravel/laravel .
  • Generate Application Key

    docker compose exec php-fpm php artisan key:generate
  • Create Storage Symlink

    docker compose exec php-fpm php artisan storage:link
  • Fix Permissions

    docker compose exec php-fpm chmod -R 777 storage bootstrap/cache
  • Run Laravel Migrations

    docker compose exec php-fpm php artisan migrate
  • Access the Container Shell

    docker exec -it php-fpm bash

Advanced Usage with Nginx

Docker-Compose with Nginx

Example of using a custom nginx config:

version: '3'
services:
  php-fpm:
    image: jkaninda/laravel-php-fpm
    container_name: php-fpm
    restart: unless-stopped
    volumes:
      - ./:/var/www/html
    networks:
      - default

  nginx-server:
    image: nginx:alpine
    container_name: nginx-server
    restart: unless-stopped
    ports:
      - 80:80
    volumes:
      - ./:/var/www/html
      - ./default.conf:/etc/nginx/conf.d/default.conf
    environment:
      - DOCUMENT_ROOT=/var/www/html/public
      - CLIENT_MAX_BODY_SIZE=20M
      - PHP_FPM_HOST=php-fpm:9000
    networks:
      - default

Nginx Configuration (default.conf)

server {
    listen 80;
    index index.php index.html;
    root /var/www/html/public;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }

    client_max_body_size 15M;
    server_tokens off;
    fastcgi_hide_header X-Powered-By;
}

Custom Build

Dockerfile Example

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

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

USER www-data

Supervisord Integration

Adding Custom Supervisor Processes

Place configurations in /etc/supervisor/conf.d/.
Example Kafka consumer process:

[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

Custom PHP Configurations

Place your custom php.ini file at:

/usr/local/etc/php/conf.d/

Storage Permissions Fix

If you encounter permission issues, run:

docker compose exec php-fpm /bin/bash
chown -R www-data:www-data /var/www/html
chmod -R 775 /var/www/html/storage

⭐️ Support the Project

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

About

🐳 Docker PHP-FPM image created to run Laravel or any php based application, 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