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

169
README.md
View File

@@ -1,16 +1,32 @@
### 🐳 **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)
[![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 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.
This image is ideal for developers looking for a streamlined, high-performance solution to deploy PHP applications with essential tools already integrated.
---
## **Links**
- [Docker Hub](https://hub.docker.com/r/jkaninda/nginx-php-fpm)
- [Github](https://github.com/jkaninda/nginx-php-fpm)
- [GitHub Repository](https://github.com/jkaninda/nginx-php-fpm)
## PHP Versions:
## **Supported PHP Versions**
- 8.4
- 8.3
- 8.2
@@ -19,78 +35,89 @@
- 7.4
- 7.2
## Specifications:
## **Specifications**
This Docker image comes pre-installed with the following:
- **PHP Extensions**:
- Composer
- OpenSSL
- XML
- PDO
- Rdkafka
- Redis
- Mbstring
- PCNTL
- ZIP
- GD
- BCMath
- Memcached
* Composer
* OpenSSL PHP Extension
* XML PHP Extension
* PDO PHP Extension
* Rdkafka PHP Extension
* Redis PHP Extension
* Mbstring PHP Extension
* PCNTL PHP Extension
* ZIP PHP Extension
* GD PHP Extension
* BCMath PHP Extension
* Memcached
* Laravel Cron Job
* Laravel Schedule
* Supervisord
* Nodejs
* NPM
- **Additional Features**:
- Laravel Cron Jobs & Scheduler
- Supervisord
- Node.js & NPM
## Simple docker-compose usage:
## **Basic Usage with Docker Compose**
```yml
### **Example `docker-compose.yml`**
```yaml
services:
app:
image: jkaninda/nginx-php-fpm:8.3
container_name: app
restart: unless-stopped
user: www-data # Optional - for production usage
user: www-data # Optional for production
volumes:
# Project root
- ./src:/var/www/html
ports:
- "80:80"
networks:
- default #if you're using networks between containers
- default
```
## Docker:
### Run
### **Commands**
#### Start the service:
```sh
docker compose up -d
```
### Create Laravel project
#### Create a new Laravel project:
```sh
docker compose exec app composer create-project --prefer-dist laravel/laravel .
```
### Artisan generate key
#### Generate application key:
```sh
docker compose exec app php artisan key:generate
```
### Storage link
#### Create a storage symlink:
```sh
docker compose exec app php artisan storage:link
```
### Fix permissions
#### Fix storage and cache permissions:
```sh
docker compose exec app chmod -R 777 storage bootstrap/cache
```
### Laravel migration
#### Run Laravel migrations:
```sh
docker compose exec app php artisan migrate
```
###
#### Access the container shell:
```sh
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'
services:
app:
@@ -102,63 +129,57 @@ services:
volumes:
# Project root
- ./:/var/www/html
- ~/.ssh:/root/.ssh # If you use private CVS
#./php.ini:/usr/local/etc/php/conf.d/php.ini # Optional, your custom php init file
- ~/.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 # Optional, or production
- LARAVEL_PROCS_NUMBER=2 # Optional, Laravel queue:work process number
- 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:
### **Default Web Root**
```
/var/www/html
```
---
## Docker run
```sh
docker compose up -d
## **Custom Build Example**
```
## Build from base
Dockerfile
### **Dockerfile**
```Dockerfile
FROM jkaninda/nginx-php-fpm:8.3
# Copy laravel project files
# Copy Laravel project files
COPY . /var/www/html
# Storage Volume
VOLUME /var/www/html/storage
WORKDIR /var/www/html
# Custom cache invalidation / optional
#ARG CACHEBUST=1
# composer install / Optional
#RUN composer install
# Fix permissions
RUN chown -R www-data:www-data /var/www/html
USER www-data
```
---
## Nginx custom config:
### Enable custom nginx config files
> /var/www/html/conf/nginx/nginx.conf
## **Custom Nginx Configuration**
> /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.
### Example:
Supervisord can be used to manage tasks or processes within the container.
### **Example Configuration for Kafka Consumer**
```conf
[program:kafkaconsume-worker]
process_name=%(program_name)s_%(process_num)02d
@@ -171,14 +192,24 @@ redirect_stderr=true
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
docker compose exec php-fpm /bin/bash
```
Then inside the container:
```sh
chown -R www-data:www-data /var/www/html/
chmod -R 775 /var/www/html/storage
```
> 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! 😊