mirror of
https://github.com/jkaninda/laravel-php-fpm.git
synced 2025-12-07 17:29:38 +01:00
Compare commits
10 Commits
5d2b1f2a49
...
docs
| Author | SHA1 | Date | |
|---|---|---|---|
| 1122dc6cff | |||
| 421512616a | |||
| 3f19dbc278 | |||
| 65b6dd8d73 | |||
| 48abada5d7 | |||
| 86b7f969d3 | |||
| 619f66f44e | |||
| f244eb704c | |||
| 8731e698bc | |||
| b90f1c3c32 |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ko_fi: jkaninda
|
||||||
98
.github/workflows/manual.yaml
vendored
98
.github/workflows/manual.yaml
vendored
@@ -7,8 +7,6 @@ on:
|
|||||||
required: true
|
required: true
|
||||||
default: 'latest'
|
default: 'latest'
|
||||||
type: string
|
type: string
|
||||||
env:
|
|
||||||
BUILDKIT_IMAGE: jkaninda/laravel-php-fpm
|
|
||||||
jobs:
|
jobs:
|
||||||
docker:
|
docker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -31,78 +29,110 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
file: "./src/docker/7.2/Dockerfile"
|
file: "./src/docker/7.2/Dockerfile"
|
||||||
push: true
|
push: true
|
||||||
tags: "${{env.BUILDKIT_IMAGE}}:7.2"
|
tags: "${{vars.BUILDKIT_IMAGE}}:7.2"
|
||||||
-
|
-
|
||||||
name: Build and push 7.3
|
name: Build and push 7.3
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
file: "./src/docker/7.3/Dockerfile"
|
file: "./src/docker/7.3/Dockerfile"
|
||||||
push: true
|
push: true
|
||||||
tags: "${{env.BUILDKIT_IMAGE}}:7.3"
|
tags: "${{vars.BUILDKIT_IMAGE}}:7.3"
|
||||||
-
|
-
|
||||||
name: Build and push 7.4
|
name: Build and push 7.4
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
file: "./src/docker/7.4/Dockerfile"
|
file: "./src/docker/7.4/Dockerfile"
|
||||||
push: true
|
push: true
|
||||||
tags: "${{env.BUILDKIT_IMAGE}}:7.4"
|
tags: "${{vars.BUILDKIT_IMAGE}}:7.4"
|
||||||
-
|
-
|
||||||
name: Build and push 8.0
|
name: Build and push 8.0
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
file: "./src/docker/8.0/Dockerfile"
|
file: "./src/docker/8.0/Dockerfile"
|
||||||
push: true
|
push: true
|
||||||
tags: "${{env.BUILDKIT_IMAGE}}:8.0"
|
tags: "${{vars.BUILDKIT_IMAGE}}:8.0"
|
||||||
-
|
-
|
||||||
name: Build and push 8.1
|
name: Build and push 8.1
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
file: "./src/docker/8.1/Dockerfile"
|
file: "./src/docker/Dockerfile"
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: "${{env.BUILDKIT_IMAGE}}:8.1"
|
build-args: |
|
||||||
-
|
phpVersion=8.1
|
||||||
name: Build and push 8.2
|
tags: "${{ vars.BUILDKIT_IMAGE }}:8.1"
|
||||||
uses: docker/build-push-action@v3
|
|
||||||
with:
|
|
||||||
file: "./src/docker/8.2/Dockerfile"
|
|
||||||
push: true
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
tags: "${{env.BUILDKIT_IMAGE}}:8.2"
|
|
||||||
-
|
-
|
||||||
name: Build and push 8.1 alpine
|
name: Build and push 8.1 alpine
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
file: "./src/docker/8.1/Dockerfile.alpine"
|
file: "./src/docker/Dockerfile.alpine"
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: |
|
build-args: |
|
||||||
"${{env.BUILDKIT_IMAGE}}:8.1-alpine"
|
phpVersion=8.1
|
||||||
|
tags: "${{ vars.BUILDKIT_IMAGE }}:8.1-alpine"
|
||||||
|
-
|
||||||
|
name: Build and push 8.2
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
file: "./src/docker/Dockerfile"
|
||||||
|
push: true
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
build-args: |
|
||||||
|
phpVersion=8.2
|
||||||
|
tags: "${{vars.BUILDKIT_IMAGE}}:8.2"
|
||||||
-
|
-
|
||||||
name: Build and push 8.2 alpine
|
name: Build and push 8.2 alpine
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
file: "./src/docker/8.2/Dockerfile.alpine"
|
file: "./src/docker/Dockerfile.alpine"
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: |
|
build-args: |
|
||||||
"${{env.BUILDKIT_IMAGE}}:8.2-alpine"
|
phpVersion=8.2
|
||||||
-
|
tags: "${{vars.BUILDKIT_IMAGE}}:8.2-alpine"
|
||||||
name: Build and push 8.3 alpine
|
|
||||||
uses: docker/build-push-action@v3
|
|
||||||
with:
|
|
||||||
file: "./src/docker/8.3/Dockerfile.alpine"
|
|
||||||
push: true
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
tags: |
|
|
||||||
"${{env.BUILDKIT_IMAGE}}:8.3-alpine"
|
|
||||||
-
|
-
|
||||||
name: Build and push 8.3
|
name: Build and push 8.3
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
file: "./src/docker/8.3/Dockerfile"
|
file: "./src/docker/Dockerfile"
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
|
build-args: |
|
||||||
|
phpVersion=8.3
|
||||||
tags: |
|
tags: |
|
||||||
"${{env.BUILDKIT_IMAGE}}:8.3"
|
"${{vars.BUILDKIT_IMAGE}}:8.3"
|
||||||
"${{env.BUILDKIT_IMAGE}}:latest"
|
-
|
||||||
|
name: Build and push 8.3 alpine
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
file: "./src/docker/Dockerfile.alpine"
|
||||||
|
push: true
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
build-args: |
|
||||||
|
phpVersion=8.3
|
||||||
|
tags: |
|
||||||
|
"${{vars.BUILDKIT_IMAGE}}:8.3-alpine"
|
||||||
|
-
|
||||||
|
name: Build and push 8.4 alpine
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
file: "./src/docker/Dockerfile.alpine"
|
||||||
|
push: true
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
build-args: |
|
||||||
|
phpVersion=8.4
|
||||||
|
tags: |
|
||||||
|
"${{vars.BUILDKIT_IMAGE}}:8.4-alpine"
|
||||||
|
-
|
||||||
|
name: Build and push 8.4
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
file: "./src/docker/Dockerfile"
|
||||||
|
push: true
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
build-args: |
|
||||||
|
phpVersion=8.4
|
||||||
|
tags: |
|
||||||
|
"${{vars.BUILDKIT_IMAGE}}:8.4"
|
||||||
|
"${{vars.BUILDKIT_IMAGE}}:latest"
|
||||||
6
.github/workflows/tests.yml
vendored
6
.github/workflows/tests.yml
vendored
@@ -6,6 +6,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
- 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
|
- name: Create Laravel project
|
||||||
run: |
|
run: |
|
||||||
composer create-project laravel/laravel laravel
|
composer create-project laravel/laravel laravel
|
||||||
|
|||||||
372
README.md
372
README.md
@@ -1,3 +1,8 @@
|
|||||||
|
### 🐳 **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.
|
||||||
|
|
||||||
[](https://github.com/jkaninda/laravel-php-fpm/actions/workflows/build.yml)
|
[](https://github.com/jkaninda/laravel-php-fpm/actions/workflows/build.yml)
|
||||||
[](https://github.com/jkaninda/laravel-php-fpm/actions/workflows/tests.yml)
|
[](https://github.com/jkaninda/laravel-php-fpm/actions/workflows/tests.yml)
|
||||||

|

|
||||||
@@ -9,17 +14,26 @@
|
|||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
# Laravel PHP-FPM Docker image
|
#### **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.
|
||||||
|
|
||||||
> 🐳 Full Docker image for a PHP-FPM container created to run Laravel or any php based applications.
|
This image is ideal for developers looking for a streamlined, high-performance solution to deploy PHP applications with essential tools already integrated.
|
||||||
|
|
||||||
> PHP Microservices ready Docker container image.
|
|
||||||
|
|
||||||
|
## Links:
|
||||||
- [Docker Hub](https://hub.docker.com/r/jkaninda/laravel-php-fpm)
|
- [Docker Hub](https://hub.docker.com/r/jkaninda/laravel-php-fpm)
|
||||||
- [Github](https://github.com/jkaninda/laravel-php-fpm)
|
- [Github](https://github.com/jkaninda/laravel-php-fpm)
|
||||||
|
---
|
||||||
|
|
||||||
|
## **Supported PHP Versions**
|
||||||
## PHP Version:
|
|
||||||
- 8.4
|
- 8.4
|
||||||
- 8.3
|
- 8.3
|
||||||
- 8.2
|
- 8.2
|
||||||
@@ -27,98 +41,49 @@
|
|||||||
- 8.0
|
- 8.0
|
||||||
- 7.4
|
- 7.4
|
||||||
- 7.2
|
- 7.2
|
||||||
## Specifications:
|
|
||||||
|
|
||||||
* Composer
|
---
|
||||||
* OpenSSL PHP Extension
|
|
||||||
* XML PHP Extension
|
|
||||||
* PDO PHP Extension
|
|
||||||
* PDO Mysql
|
|
||||||
* PDO Pgsql
|
|
||||||
* Rdkafka PHP Extension
|
|
||||||
* Redis PHP Extension
|
|
||||||
* Mbstring PHP Extension
|
|
||||||
* PCNTL PHP Extension
|
|
||||||
* ZIP PHP Extension
|
|
||||||
* GD PHP Extension
|
|
||||||
* BCMath PHP Extension
|
|
||||||
* Memcached
|
|
||||||
* Opcache
|
|
||||||
* Laravel Cron Job
|
|
||||||
* Laravel Schedule
|
|
||||||
* Laravel Envoy
|
|
||||||
* Supervisord
|
|
||||||
* Node
|
|
||||||
* NPM
|
|
||||||
|
|
||||||
## Simple docker-compose usage:
|
## **Specifications**
|
||||||
|
|
||||||
```yml
|
### **PHP Extensions**
|
||||||
version: '3'
|
- 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**
|
||||||
|
```yaml
|
||||||
services:
|
services:
|
||||||
php-fpm:
|
php-fpm:
|
||||||
image: jkaninda/laravel-php-fpm:latest
|
image: jkaninda/laravel-php-fpm:latest
|
||||||
container_name: php-fpm
|
container_name: php-fpm
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
user: www-data #Use www-data user for production usage
|
user: www-data # For production
|
||||||
volumes:
|
volumes:
|
||||||
#Project root
|
- ./:/var/www/html
|
||||||
- ./src:/var/www/html
|
networks:
|
||||||
networks:
|
- default
|
||||||
- default #if you're using networks between containers
|
nginx-server:
|
||||||
|
|
||||||
```
|
|
||||||
## Docker:
|
|
||||||
### Run
|
|
||||||
```sh
|
|
||||||
docker compose up -d
|
|
||||||
```
|
|
||||||
### Create Laravel project
|
|
||||||
```sh
|
|
||||||
docker compose exec php-fpm composer create-project --prefer-dist laravel/laravel .
|
|
||||||
```
|
|
||||||
### Artisan generate key
|
|
||||||
```sh
|
|
||||||
docker compose exec php-fpm php artisan key:generate
|
|
||||||
```
|
|
||||||
### Storage link
|
|
||||||
```sh
|
|
||||||
docker compose exec php-fpm php artisan storage:link
|
|
||||||
```
|
|
||||||
### Fix permissions
|
|
||||||
```sh
|
|
||||||
docker compose exec php-fpm chmod -R 777 storage bootstrap/cache
|
|
||||||
```
|
|
||||||
### Laravel migration
|
|
||||||
```sh
|
|
||||||
docker compose exec php-fpm php artisan migrate
|
|
||||||
```
|
|
||||||
###
|
|
||||||
```sh
|
|
||||||
docker exec -it php-fpm bash
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configurations
|
|
||||||
|
|
||||||
- Supervisor config folder: /etc/supervisor/conf.d/
|
|
||||||
- PHP ini config foler /usr/local/etc/php/conf.d/
|
|
||||||
|
|
||||||
## Example Laravel-php-fpm with nginx:
|
|
||||||
### docker-compose.yml
|
|
||||||
```yml
|
|
||||||
services:
|
|
||||||
php-fpm:
|
|
||||||
image: jkaninda/laravel-php-fpm
|
|
||||||
container_name: php-fpm
|
|
||||||
restart: unless-stopped
|
|
||||||
volumes:
|
|
||||||
#Project root
|
|
||||||
- ./:/var/www/html
|
|
||||||
networks:
|
|
||||||
- default #if you're using networks between containers
|
|
||||||
#Nginx server
|
|
||||||
nginx-server:
|
|
||||||
image: jkaninda/nginx-fpm:alpine
|
image: jkaninda/nginx-fpm:alpine
|
||||||
container_name: nginx-server
|
container_name: nginx-server
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -132,64 +97,64 @@ services:
|
|||||||
- PHP_FPM_HOST=php-fpm:9000
|
- PHP_FPM_HOST=php-fpm:9000
|
||||||
networks:
|
networks:
|
||||||
- default
|
- default
|
||||||
|
|
||||||
```
|
|
||||||
## Simple Nginx config file content
|
|
||||||
### default.conf
|
|
||||||
|
|
||||||
```conf
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
index index.php index.html;
|
|
||||||
error_log /var/log/nginx/error.log;
|
|
||||||
access_log /var/log/nginx/access.log;
|
|
||||||
##Public directory
|
|
||||||
root /var/www/html/public;
|
|
||||||
location ~ \.php$ {
|
|
||||||
try_files $uri =404;
|
|
||||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
|
||||||
## PHP FPM ( php-fpm:9000 ) or [servicename:9000]
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
client_max_body_size 15M;
|
|
||||||
server_tokens off;
|
|
||||||
|
|
||||||
# Hide PHP headers
|
|
||||||
fastcgi_hide_header X-Powered-By;
|
|
||||||
fastcgi_hide_header X-CF-Powered-By;
|
|
||||||
fastcgi_hide_header X-Runtime;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
try_files $uri $uri/ /index.php?$query_string;
|
|
||||||
gzip_static on;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Advanced Laravel-php-fpm with nginx:
|
### **Basic Commands**
|
||||||
### docker-compose.yml
|
- **Start Containers**
|
||||||
```yml
|
```sh
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Create a Laravel Project**
|
||||||
|
```sh
|
||||||
|
docker compose exec php-fpm composer create-project --prefer-dist laravel/laravel .
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Generate Application Key**
|
||||||
|
```sh
|
||||||
|
docker compose exec php-fpm php artisan key:generate
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Create Storage Symlink**
|
||||||
|
```sh
|
||||||
|
docker compose exec php-fpm php artisan storage:link
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Fix Permissions**
|
||||||
|
```sh
|
||||||
|
docker compose exec php-fpm chmod -R 777 storage bootstrap/cache
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Run Laravel Migrations**
|
||||||
|
```sh
|
||||||
|
docker compose exec php-fpm php artisan migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Access the Container Shell**
|
||||||
|
```sh
|
||||||
|
docker exec -it php-fpm bash
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## **Advanced Usage with Nginx**
|
||||||
|
|
||||||
|
### **Docker-Compose with Nginx**
|
||||||
|
Example of using a custom nginx config:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
services:
|
services:
|
||||||
php-fpm:
|
php-fpm:
|
||||||
image: jkaninda/laravel-php-fpm
|
image: jkaninda/laravel-php-fpm
|
||||||
container_name: php-fpm
|
container_name: php-fpm
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
#Project root
|
- ./:/var/www/html
|
||||||
- ./:/var/www/html
|
networks:
|
||||||
- ~/.ssh:/root/.ssh # If you use private CVS
|
- default
|
||||||
- ./php.ini:/usr/local/etc/php/conf.d/php.ini # Optional, your custom php init file
|
|
||||||
environment:
|
nginx-server:
|
||||||
- APP_ENV=development # Optional, or production
|
|
||||||
#- LARAVEL_PROCS_NUMBER=1 # Optional, Laravel queue:work process number
|
|
||||||
#Nginx server
|
|
||||||
nginx-server:
|
|
||||||
image: nginx:alpine
|
image: nginx:alpine
|
||||||
container_name: nginx-server
|
container_name: nginx-server
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -198,46 +163,68 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./:/var/www/html
|
- ./:/var/www/html
|
||||||
- ./default.conf:/etc/nginx/conf.d/default.conf
|
- ./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:
|
networks:
|
||||||
- default
|
- default
|
||||||
volumes:
|
|
||||||
storage-data:
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docker run
|
### **Nginx Configuration (default.conf)**
|
||||||
```sh
|
|
||||||
docker compose up -d
|
|
||||||
|
|
||||||
|
```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;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
## Build from base
|
|
||||||
|
|
||||||
Dockerfile
|
---
|
||||||
|
|
||||||
|
## **Custom Build**
|
||||||
|
|
||||||
|
### **Dockerfile Example**
|
||||||
```Dockerfile
|
```Dockerfile
|
||||||
FROM jkaninda/laravel-php-fpm:8.3
|
FROM jkaninda/laravel-php-fpm:8.3
|
||||||
# Copy laravel project files
|
# Copy Laravel project files
|
||||||
COPY . /var/www/html
|
COPY . /var/www/html
|
||||||
# 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
|
|
||||||
# Run 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
|
||||||
```
|
```
|
||||||
## Supervisord
|
|
||||||
### Add 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.
|
### **Adding Custom Supervisor Processes**
|
||||||
### Example:
|
Place configurations in `/etc/supervisor/conf.d/`.
|
||||||
|
Example Kafka consumer process:
|
||||||
```conf
|
```conf
|
||||||
[program:kafkaconsume-worker]
|
[program:kafkaconsume-worker]
|
||||||
process_name=%(program_name)s_%(process_num)02d
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
@@ -250,21 +237,50 @@ redirect_stderr=true
|
|||||||
stdout_logfile=/var/www/html/storage/logs/kafka.log
|
stdout_logfile=/var/www/html/storage/logs/kafka.log
|
||||||
```
|
```
|
||||||
|
|
||||||
### Custom php.ini
|
---
|
||||||
> /var/www/html/conf/php/php.ini
|
|
||||||
|
|
||||||
### Storage permision issue
|
## **Custom PHP Configurations**
|
||||||
```sh
|
Place your custom `php.ini` file at:
|
||||||
docker compose exec php-fpm /bin/bash
|
```
|
||||||
```
|
/usr/local/etc/php/conf.d/
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## **Storage Permissions Fix**
|
||||||
|
If you encounter permission issues, run:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
chown -R www-data:www-data /var/www/html
|
docker compose exec php-fpm /bin/bash
|
||||||
```
|
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?
|
||||||
|
|
||||||
> P.S. please give a star if you like it :wink:
|
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 Let’s 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!
|
||||||
|
|
||||||
|
|||||||
29
compose.yaml
Normal file
29
compose.yaml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
services:
|
||||||
|
php-fpm:
|
||||||
|
image: jkaninda/laravel-php-fpm
|
||||||
|
container_name: php-fpm
|
||||||
|
restart: unless-stopped
|
||||||
|
user: www-data #Use www-data user production usage
|
||||||
|
volumes:
|
||||||
|
#Project root
|
||||||
|
- ./:/var/www/html
|
||||||
|
networks:
|
||||||
|
- web #if you're using networks between containers
|
||||||
|
#Nginx server
|
||||||
|
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:
|
||||||
|
- web
|
||||||
|
networks:
|
||||||
|
web:
|
||||||
|
external: false
|
||||||
@@ -1,63 +1,79 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Logging functions
|
||||||
|
log() {
|
||||||
|
local level=$1
|
||||||
|
shift
|
||||||
|
{ set +x; } 2> /dev/null
|
||||||
|
echo "[$level] $@"
|
||||||
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
log "INFO" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
warning() {
|
||||||
|
log "WARNING" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
fatal() {
|
||||||
|
log "ERROR" "$@" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Banner
|
||||||
echo ""
|
echo ""
|
||||||
echo "***********************************************************"
|
echo "***********************************************************"
|
||||||
echo " Starting LARAVEL PHP-FPM Container "
|
echo " Starting LARAVEL PHP-FPM Container "
|
||||||
echo "***********************************************************"
|
echo "***********************************************************"
|
||||||
|
|
||||||
set -e
|
# Check if the artisan file exists
|
||||||
info() {
|
ARTISAN_PATH="/var/www/html/artisan"
|
||||||
{ set +x; } 2> /dev/null
|
if [[ -f "$ARTISAN_PATH" ]]; then
|
||||||
echo '[INFO] ' "$@"
|
info "Artisan file found, creating Laravel supervisor config..."
|
||||||
}
|
|
||||||
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..."
|
|
||||||
##Create Laravel Scheduler process
|
|
||||||
TASK=/etc/supervisor/conf.d/laravel-worker.conf
|
|
||||||
touch $TASK
|
|
||||||
cat > "$TASK" <<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"
|
|
||||||
autostart=true
|
|
||||||
autorestart=true
|
|
||||||
numprocs=1
|
|
||||||
user=$USER_NAME
|
|
||||||
stdout_logfile=/var/log/laravel_scheduler.out.log
|
|
||||||
redirect_stderr=true
|
|
||||||
|
|
||||||
[program:Laravel-worker]
|
# Create Laravel Supervisor config
|
||||||
process_name=%(program_name)s_%(process_num)02d
|
SUPERVISOR_TASK="/etc/supervisor/conf.d/laravel-worker.conf"
|
||||||
command=php /var/www/html/artisan queue:work --sleep=3 --tries=3
|
cat > "$SUPERVISOR_TASK" <<EOF
|
||||||
autostart=true
|
[program:Laravel-scheduler]
|
||||||
autorestart=true
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
numprocs=$LARAVEL_PROCS_NUMBER
|
command=/bin/sh -c "while true; do php $ARTISAN_PATH schedule:run --verbose --no-interaction & sleep 60; done"
|
||||||
user=$USER_NAME
|
autostart=true
|
||||||
redirect_stderr=true
|
autorestart=true
|
||||||
stdout_logfile=/var/log/laravel_worker.log
|
numprocs=1
|
||||||
|
user=$USER_NAME
|
||||||
|
stdout_logfile=/var/log/laravel_scheduler.out.log
|
||||||
|
redirect_stderr=true
|
||||||
|
|
||||||
|
[program:Laravel-worker]
|
||||||
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
|
command=php $ARTISAN_PATH queue:work --sleep=3 --tries=3
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
numprocs=$LARAVEL_PROCS_NUMBER
|
||||||
|
user=$USER_NAME
|
||||||
|
redirect_stderr=true
|
||||||
|
stdout_logfile=/var/log/laravel_worker.log
|
||||||
EOF
|
EOF
|
||||||
info "Laravel supervisor config created"
|
|
||||||
|
info "Laravel supervisor config created at $SUPERVISOR_TASK"
|
||||||
else
|
else
|
||||||
info "artisan file not found"
|
info "Artisan file not found at $ARTISAN_PATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Check if php.ini file exists
|
# Check if custom php.ini file exists
|
||||||
if [ -f /var/www/html/conf/php/php.ini ]; then
|
PHP_INI_SOURCE="/var/www/html/conf/php/php.ini"
|
||||||
cp /var/www/html/conf/php/php.ini $PHP_INI_DIR/conf.d/
|
PHP_INI_TARGET="$PHP_INI_DIR/conf.d/php.ini"
|
||||||
info "Custom php.ini file found and copied in $PHP_INI_DIR/conf.d/"
|
|
||||||
|
if [[ -f "$PHP_INI_SOURCE" ]]; then
|
||||||
|
cp "$PHP_INI_SOURCE" "$PHP_INI_TARGET"
|
||||||
|
info "Custom php.ini file found and copied to $PHP_INI_TARGET"
|
||||||
else
|
else
|
||||||
info "Custom php.ini file not found"
|
info "Custom php.ini file not found at $PHP_INI_SOURCE"
|
||||||
info "If you want to add a custom php.ini file, you add it in /var/www/html/conf/php/php.ini"
|
info "To use a custom php.ini file, place it at $PHP_INI_SOURCE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Start Supervisor
|
||||||
supervisord -c /etc/supervisor/supervisord.conf
|
supervisord -c /etc/supervisor/supervisord.conf
|
||||||
@@ -12,7 +12,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- 3306:3306
|
- 3306:3306
|
||||||
php-fpm:
|
php-fpm:
|
||||||
image: jkaninda/laravel-php-fpm
|
image: jkaninda/laravel-php-fpm:latest
|
||||||
container_name: php-fpm
|
container_name: php-fpm
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
#user: www-data #Use www-data user production usage
|
#user: www-data #Use www-data user production usage
|
||||||
|
|||||||
Reference in New Issue
Block a user