Update core features
Some checks failed
Test / integration (push) Failing after 3s

This commit is contained in:
2024-12-27 18:59:07 +01:00
parent a6c5254e05
commit fa948d34c5

243
README.md
View File

@@ -1,164 +1,185 @@
### 🐳 **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](https://github.com/jkaninda/nginx-php-fpm/actions/workflows/build.yml/badge.svg)](https://github.com/jkaninda/nginx-php-fpm/actions/workflows/build.yml) [![Build](https://github.com/jkaninda/nginx-php-fpm/actions/workflows/build.yml/badge.svg)](https://github.com/jkaninda/nginx-php-fpm/actions/workflows/build.yml)
[![Tests](https://github.com/jkaninda/nginx-php-fpm/actions/workflows/tests.yml/badge.svg)](https://github.com/jkaninda/nginx-php-fpm/actions/workflows/tests.yml) [![Tests](https://github.com/jkaninda/nginx-php-fpm/actions/workflows/tests.yml/badge.svg)](https://github.com/jkaninda/nginx-php-fpm/actions/workflows/tests.yml)
![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/jkaninda/nginx-php-fpm?style=flat-square) ![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/jkaninda/nginx-php-fpm?style=flat-square)
![Docker Pulls](https://img.shields.io/docker/pulls/jkaninda/nginx-php-fpm?style=flat-square) ![Docker Pulls](https://img.shields.io/docker/pulls/jkaninda/nginx-php-fpm?style=flat-square)
# Nginx PHP-FPM Docker image
> 🐳 Full Docker image for Nginx PHP-FPM container created to run Laravel or any php based applications. #### **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.
- [Docker Hub](https://hub.docker.com/r/jkaninda/nginx-php-fpm) This image is ideal for developers looking for a streamlined, high-performance solution to deploy PHP applications with essential tools already integrated.
- [Github](https://github.com/jkaninda/nginx-php-fpm)
## PHP Versions: ---
- 8.4 ## **Links**
- 8.3 - [Docker Hub](https://hub.docker.com/r/jkaninda/nginx-php-fpm)
- 8.2 - [GitHub Repository](https://github.com/jkaninda/nginx-php-fpm)
- 8.1
- 8.0
- 7.4
- 7.2
## Specifications: ## **Supported PHP Versions**
- 8.4
- 8.3
- 8.2
- 8.1
- 8.0
- 7.4
- 7.2
* Composer ## **Specifications**
* OpenSSL PHP Extension This Docker image comes pre-installed with the following:
* XML PHP Extension - **PHP Extensions**:
* PDO PHP Extension - Composer
* Rdkafka PHP Extension - OpenSSL
* Redis PHP Extension - XML
* Mbstring PHP Extension - PDO
* PCNTL PHP Extension - Rdkafka
* ZIP PHP Extension - Redis
* GD PHP Extension - Mbstring
* BCMath PHP Extension - PCNTL
* Memcached - ZIP
* Laravel Cron Job - GD
* Laravel Schedule - BCMath
* Supervisord - Memcached
* Nodejs
* NPM
## Simple docker-compose usage: - **Additional Features**:
- Laravel Cron Jobs & Scheduler
- Supervisord
- Node.js & NPM
```yml ## **Basic Usage with Docker Compose**
### **Example `docker-compose.yml`**
```yaml
services: services:
app: app:
image: jkaninda/nginx-php-fpm:8.3 image: jkaninda/nginx-php-fpm:8.3
container_name: app container_name: app
restart: unless-stopped restart: unless-stopped
user: www-data # Optional - for production usage user: www-data # Optional for production
volumes: volumes:
#Project root # Project root
- ./src:/var/www/html - ./src:/var/www/html
ports: ports:
- "80:80" - "80:80"
networks: networks:
- default #if you're using networks between containers - default
```
``` ### **Commands**
## Docker:
### Run #### Start the service:
```sh ```sh
docker compose up -d docker compose up -d
``` ```
### Create Laravel project
#### Create a new Laravel project:
```sh ```sh
docker compose exec app composer create-project --prefer-dist laravel/laravel . docker compose exec app composer create-project --prefer-dist laravel/laravel .
``` ```
### Artisan generate key
#### Generate application key:
```sh ```sh
docker compose exec app php artisan key:generate docker compose exec app php artisan key:generate
``` ```
### Storage link
#### Create a storage symlink:
```sh ```sh
docker compose exec app php artisan storage:link docker compose exec app php artisan storage:link
``` ```
### Fix permissions
#### Fix storage and cache permissions:
```sh ```sh
docker compose exec app chmod -R 777 storage bootstrap/cache docker compose exec app chmod -R 777 storage bootstrap/cache
``` ```
### Laravel migration
#### Run Laravel migrations:
```sh ```sh
docker compose exec app php artisan migrate docker compose exec app php artisan migrate
``` ```
###
#### Access the container shell:
```sh ```sh
docker exec -it app bash docker exec -it app bash
``` ```
## Advanced Nignx-php-fpm: ---
### docker-compose.yml
```yml ## **Advanced Nginx PHP-FPM Setup**
### **Extended `docker-compose.yml` Example**
```yaml
version: '3' version: '3'
services: services:
app: app:
image: jkaninda/nginx-php-fpm image: jkaninda/nginx-php-fpm
container_name: app container_name: app
restart: unless-stopped restart: unless-stopped
ports: ports:
- "80:80" - "80:80"
volumes: volumes:
#Project root # Project root
- ./:/var/www/html - ./:/var/www/html
- ~/.ssh:/root/.ssh # If you use private CVS - ~/.ssh:/root/.ssh # Use private CVS if needed
#./php.ini:/usr/local/etc/php/conf.d/php.ini # Optional, your custom php init file # Optional custom PHP config
environment: # - ./php.ini:/usr/local/etc/php/conf.d/php.ini
- APP_ENV=development # Optional, or production environment:
- LARAVEL_PROCS_NUMBER=2 # Optional, Laravel queue:work process number - APP_ENV=development # or production
#- CLIENT_MAX_BODY_SIZE=20M # Optional - LARAVEL_PROCS_NUMBER=2 # Optional: Queue worker processes
#- DOMAIN=example.com # Optional # - CLIENT_MAX_BODY_SIZE=20M # Optional
- DOCUMENT_ROOT=/var/www/html #Optional # - DOMAIN=example.com # Optional
- DOCUMENT_ROOT=/var/www/html # Optional
``` ```
Default web root:
### **Default Web Root**
``` ```
/var/www/html /var/www/html
``` ```
---
## Docker run ## **Custom Build Example**
```sh
docker compose up -d
``` ### **Dockerfile**
## Build from base
Dockerfile
```Dockerfile ```Dockerfile
FROM jkaninda/nginx-php-fpm:8.3 FROM jkaninda/nginx-php-fpm:8.3
# Copy laravel project files # Copy Laravel project files
COPY . /var/www/html COPY . /var/www/html
# Storage Volume # Storage Volume
VOLUME /var/www/html/storage VOLUME /var/www/html/storage
WORKDIR /var/www/html WORKDIR /var/www/html
# Custom cache invalidation / optional
#ARG CACHEBUST=1
# composer install / Optional
#RUN composer install
# Fix permissions # Fix permissions
RUN chown -R www-data:www-data /var/www/html RUN chown -R www-data:www-data /var/www/html
USER www-data USER www-data
``` ```
---
## Nginx custom config: ## **Custom Nginx Configuration**
### Enable custom nginx config files
> /var/www/html/conf/nginx/nginx.conf
> /var/www/html/conf/nginx/nginx-site.conf 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 ---
### Add more supervisor process in
> /etc/supervisor/conf.d/
In case you want to execute and maintain a task or process with supervisor. ## **Supervisord Integration**
Find below an example with Apache Kafka, when you want to maintain a consumer process. Supervisord can be used to manage tasks or processes within the container.
### Example:
### **Example Configuration for Kafka Consumer**
```conf ```conf
[program:kafkaconsume-worker] [program:kafkaconsume-worker]
process_name=%(program_name)s_%(process_num)02d process_name=%(program_name)s_%(process_num)02d
@@ -171,14 +192,24 @@ redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/kafka.log stdout_logfile=/var/www/html/storage/logs/kafka.log
``` ```
### Storage permision issue ---
## **Fixing Storage Permissions**
If you encounter storage permission issues, run the following commands:
```sh ```sh
docker compose exec php-fpm /bin/bash docker compose exec php-fpm /bin/bash
```
```sh
chown -R www-data:www-data /var/www/html/
``` ```
> chmod -R 775 /var/www/html/storage Then inside the container:
```sh
chown -R www-data:www-data /var/www/html/
chmod -R 775 /var/www/html/storage
```
> P.S. please give a star if you like it :wink: ---
## **Star the Project**
If you find this project useful, please give it a ⭐️ on GitHub to show your support! 😊