Compare commits

..

14 Commits

Author SHA1 Message Date
402874a099 update readme
Some checks failed
Test / integration (push) Has been cancelled
2025-07-27 07:21:50 +02:00
93ddde9b30 Merge pull request #40 from jkaninda/dev
Some checks failed
Build / docker (push) Has been cancelled
Test / integration (push) Has been cancelled
Create FUNDING.yml
2025-07-19 02:29:52 +02:00
f59bd88d2e Create FUNDING.yml 2025-07-19 02:29:30 +02:00
091ebc6b09 Optimization of entrypoint (#39)
Some checks failed
Test / integration (push) Has been cancelled
Build / docker (push) Has been cancelled
2025-05-11 09:39:25 +02:00
258580b107 Merge pull request #37 from jkaninda/develop
Some checks failed
Build / docker (push) Failing after 8s
Test / integration (push) Failing after 2s
Update core features
2024-12-27 19:00:04 +01:00
fa948d34c5 Update core features
Some checks failed
Test / integration (push) Failing after 3s
2024-12-27 18:59:07 +01:00
a6c5254e05 Merge pull request #36 from jkaninda/develop
Add php 8.4
2024-11-24 13:18:41 +01:00
745d85b999 Merge pull request #35 from jkaninda/develop
Update readme
2024-11-16 20:56:09 +01:00
a73dc861d3 Merge pull request #34 from jkaninda/develop
fix ci
2024-11-16 20:48:30 +01:00
2e77ee7a6d Merge pull request #33 from jkaninda/develop
add php 8.4 RC
2024-11-16 20:45:17 +01:00
566d21fb6d Merge pull request #32 from jkaninda/develop
Add LICENSE
2024-10-10 08:14:43 +02:00
193e19df92 Merge pull request #31 from jkaninda/develop
chore: upgrade Node version from 17 to 20
2024-09-18 20:54:08 +02:00
6c7be22d06 Merge pull request #30 from jkaninda/develop
Update PHP version
2024-06-08 08:37:14 +02:00
3895edac70 Merge pull request #29 from jkaninda/develop
chore: update php version
2024-03-05 07:37:12 +01:00
5 changed files with 262 additions and 203 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
ko_fi: jkaninda

View File

@@ -6,6 +6,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Build the Docker image
- name: Build Docker Image
run: |
docker buildx build -f src/docker/Dockerfile --build-arg phpVersion=8.4 -t ${{ vars.BUILDKIT_IMAGE }}:latest --load .
- name: Verify Docker images
run: |
docker images
- name: Create Laravel project
run: |
composer create-project laravel/laravel laravel

194
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,49 @@ 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
---
### Explore Another Project: Goma Gateway
Are you building a microservices architecture?
Do you need a powerful yet lightweight API Gateway or a high-performance reverse proxy to secure and manage your services effortlessly?
Check out my other project — **[Goma Gateway](https://github.com/jkaninda/goma-gateway)**.
**Goma Gateway** is a high-performance, declarative API Gateway built for modern microservices. It comes with a rich set of built-in middleware, including:
* Basic, JWT, OAuth2, LDAP, and ForwardAuth authentication
* Caching and rate limiting
* Bot detection
* Built-in load balancing
* Simple configuration with minimal overhead
* ...and more!
**Protocol support:** REST, GraphQL, gRPC, TCP, and UDP
**Security:** Automatic HTTPS via Lets Encrypt or use your own TLS certificates
Whether you're managing internal APIs or exposing public endpoints, **Goma Gateway** helps you do it efficiently, securely, and with minimal complexity.
---
## ⭐️ **Support the Project**
If this project helped you, do not skip on giving it a star. Thanks!
> P.S. please give a star if you like it :wink:

View File

@@ -1,37 +1,33 @@
#!/bin/sh
set -e
echo ""
echo "***********************************************************"
echo " Starting NGINX PHP-FPM Docker Container "
echo "***********************************************************"
set -e
set -e
info() {
{ set +x; } 2> /dev/null
echo '[INFO] ' "$@"
}
warning() {
{ set +x; } 2> /dev/null
echo '[WARNING] ' "$@"
}
fatal() {
{ set +x; } 2> /dev/null
echo '[ERROR] ' "$@" >&2
exit 1
}
## Check if the artisan file exists
if [ -f /var/www/html/artisan ]; then
info "Artisan file found, creating laravel supervisor config"
# Set DocumentRoot to the Laravel project directory
export DOCUMENT_ROOT=/var/www/html/public
##Create Laravel Scheduler process
TASK=/etc/supervisor/conf.d/laravel-worker.conf
touch $TASK
cat > "$TASK" <<EOF
# Logging functions
info() { echo "[INFO] $*"; }
warning() { echo "[WARNING] $*"; }
fatal() { echo "[ERROR] $*" >&2; exit 1; }
ARTISAN_FILE="/var/www/html/artisan"
SUPERVISOR_CONF_DIR="/etc/supervisor/conf.d"
NGINX_CONF_DIR="/etc/nginx/conf.d"
CUSTOM_NGINX_CONF="/var/www/html/conf/nginx"
CUSTOM_SUPERVISOR_CONF="/var/www/html/conf/worker/supervisor.conf"
DOCUMENT_ROOT="/var/www/html/public"
# Laravel Supervisor Setup
setup_laravel_supervisor() {
info "Artisan file found, creating Laravel supervisor config"
export DOCUMENT_ROOT
cat > "$SUPERVISOR_CONF_DIR/laravel-worker.conf" <<EOF
[program:Laravel-scheduler]
process_name=%(program_name)s_%(process_num)02d
command=/bin/sh -c "while [ true ]; do (php /var/www/html/artisan schedule:run --verbose --no-interaction &); sleep 60; done"
command=/bin/sh -c "while true; do (php /var/www/html/artisan schedule:run --verbose --no-interaction &); sleep 60; done"
autostart=true
autorestart=true
numprocs=1
@@ -49,55 +45,51 @@ if [ -f /var/www/html/artisan ]; then
redirect_stderr=true
stdout_logfile=/var/log/laravel_worker.log
EOF
info "Laravel supervisor config created"
else
info "artisan file not found"
fi
# Enable custom nginx config files if they exist
if [ -f /var/www/html/conf/nginx/nginx.conf ]; then
cp /var/www/html/conf/nginx/nginx.conf /etc/nginx/nginx.conf
info "Laravel supervisor config created"
}
# Nginx Config Setup
setup_nginx_config() {
if [ -f "$CUSTOM_NGINX_CONF/nginx.conf" ]; then
cp "$CUSTOM_NGINX_CONF/nginx.conf" /etc/nginx/nginx.conf
info "Using custom nginx.conf"
fi
if [ -f /var/www/html/conf/nginx/nginx-site.conf ]; then
if [ -f "$CUSTOM_NGINX_CONF/nginx-site.conf" ]; then
info "Custom nginx site config found"
rm /etc/nginx/conf.d/default.conf
cp /var/www/html/conf/nginx/nginx-site.conf /etc/nginx/conf.d/default.conf
rm -f "$NGINX_CONF_DIR/default.conf"
cp "$CUSTOM_NGINX_CONF/nginx-site.conf" "$NGINX_CONF_DIR/default.conf"
info "Start nginx with custom server config..."
else
info "nginx-site.conf not found"
info "If you want to use custom configs, create config file in /var/www/html/conf/nginx/nginx-site.conf"
info "If you want to use custom configs, create it at $CUSTOM_NGINX_CONF/nginx-site.conf"
info "Start nginx with default config..."
rm -f /etc/nginx/conf.d/default.conf
TASK=/etc/nginx/conf.d/default.conf
touch $TASK
cat > "$TASK" <<EOF
cat > "$NGINX_CONF_DIR/default.conf" <<EOF
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name $DOMAIN;
# Add index.php to setup Nginx, PHP & PHP-FPM config
index index.php index.html index.htm index.nginx-debian.html;
root $DOCUMENT_ROOT;
index index.php index.html index.htm;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root $DOCUMENT_ROOT;
# pass PHP scripts on Nginx to FastCGI (PHP-FPM) server
location ~ \.php$ {
location ~ \.php\$ {
try_files \$uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Nginx php-fpm config:
fastcgi_split_path_info ^(.+\.php)(/.+)\$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param PATH_INFO \$fastcgi_path_info;
}
client_max_body_size $CLIENT_MAX_BODY_SIZE;
server_tokens off;
# Hide PHP headers
fastcgi_hide_header X-Powered-By;
fastcgi_hide_header X-CF-Powered-By;
fastcgi_hide_header X-Runtime;
@@ -106,27 +98,30 @@ if [ -f /var/www/html/conf/nginx/nginx-site.conf ]; then
try_files \$uri \$uri/ /index.php\$is_args\$args;
gzip_static on;
}
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
# deny access to Apache .htaccess on Nginx with PHP,
# if Apache and Nginx document roots concur
location ~ \.css\$ { add_header Content-Type text/css; }
location ~ \.js\$ { add_header Content-Type application/x-javascript; }
location ~ /\.ht { deny all; }
location ~ /\.svn/ {deny all;}
location ~ /\.git/ {deny all;}
location ~ /\.hg/ {deny all;}
location ~ /\.bzr/ {deny all;}
location ~ /\.(svn|git|hg|bzr)/ { deny all; }
}
EOF
fi
## Check if the supervisor config file exists
if [ -f /var/www/html/conf/worker/supervisor.conf ]; then
info "Custom supervisor config found"
cp /var/www/html/conf/worker/supervisor.conf /etc/supervisor/conf.d/supervisor.conf
fi
## Start Supervisord
supervisord -c /etc/supervisor/supervisord.conf
}
# Load custom supervisor config if exists
load_custom_supervisor_config() {
if [ -f "$CUSTOM_SUPERVISOR_CONF" ]; then
info "Custom supervisor config found"
cp "$CUSTOM_SUPERVISOR_CONF" "$SUPERVISOR_CONF_DIR/supervisor.conf"
fi
}
# Main Execution
[ -f "$ARTISAN_FILE" ] && setup_laravel_supervisor || info "artisan file not found"
setup_nginx_config
load_custom_supervisor_config
# Start Supervisor
supervisord -c /etc/supervisor/supervisord.conf

0
version Normal file
View File