Compare commits

...

33 Commits

Author SHA1 Message Date
f244eb704c Update core features
Some checks failed
Tests / integration (push) Failing after 3s
2024-12-27 19:20:49 +01:00
8731e698bc Merge pull request #83 from jkaninda/develop
Some checks failed
Build / docker (push) Failing after 1m17s
Tests / integration (push) Failing after 5s
ci: update manual build
2024-12-13 19:55:18 +01:00
5d2b1f2a49 Merge pull request #82 from jkaninda/develop
Add PHP 8.4
2024-11-24 13:22:41 +01:00
d4f8c74eb2 Merge pull request #81 from jkaninda/develop
Add add php 8.4 RC
2024-11-17 19:17:15 +01:00
1733a634a3 Merge pull request #80 from Androbin/patch-1
Create LICENSE
2024-10-10 08:06:40 +02:00
Robin Richtsfeld
8b009d1b3c Create LICENSE 2024-10-10 07:28:19 +02:00
b3850050fc Merge pull request #78 from jkaninda/develop
Update PHP and Node version
2024-09-18 21:16:55 +02:00
23bd4ca852 Merge pull request #77 from jkaninda/develop
chore: update php version
2024-03-05 07:35:49 +01:00
8539386b7a Merge pull request #76 from jkaninda/develop
docs: update README
2024-01-13 14:22:02 +01:00
cc5d71f1e7 Merge pull request #75 from jkaninda/develop
chore: redirect php-fpm process to supervisor's log, refactoring of code
2024-01-13 14:20:11 +01:00
10007c3d37 Merge pull request #74 from jkaninda/develop
Update README
2024-01-06 15:06:26 +01:00
5c95007a33 Merge pull request #73 from jkaninda/develop
Refactoring
2024-01-06 15:03:15 +01:00
7c1e92f932 Merge pull request #72 from jkaninda/develop
Update test compose.yaml
2024-01-06 12:49:50 +01:00
393179c22a Merge pull request #71 from jkaninda/develop
Update github action
2024-01-06 12:28:46 +01:00
34970e57b8 Merge pull request #70 from jkaninda/develop
Update php version, fix permission issue
2024-01-06 12:17:43 +01:00
673a481044 Merge pull request #69 from jkaninda/develop
Develop
2023-12-16 07:22:43 +01:00
5dea6fe79a Merge pull request #67 from jkaninda/develop
Laravel database migration test
2023-12-10 22:42:51 +01:00
b87513e560 Merge pull request #66 from jkaninda/develop
Refactoring
2023-12-09 21:41:09 +01:00
c4ce43d531 Merge pull request #65 from jkaninda/develop
Develop
2023-12-09 18:27:59 +01:00
5f69345fd0 Merge pull request #64 from jkaninda/develop
Develop
2023-12-08 18:30:43 +01:00
f409343ecd Merge pull request #61 from jkaninda/develop
Update README
2023-11-13 15:18:23 +01:00
1045c2eb9a Merge pull request #60 from jkaninda/develop
Develop
2023-11-13 07:23:21 +01:00
d1b60c02f9 Merge pull request #57 from jkaninda/develop
Update PHP Version
2023-10-11 15:18:42 +02:00
3537726725 Merge pull request #56 from jkaninda/develop
Add PHP Opcache extension
2023-09-20 05:44:55 +02:00
b6858c9097 Merge pull request #54 from jkaninda/develop
Update Node version
2023-09-12 14:19:10 +02:00
acfb10dbb9 Merge pull request #53 from jkaninda/develop
Update Node version, refactoring
2023-09-12 14:13:01 +02:00
a066c2f8ec Merge pull request #52 from jkaninda/develop
Update Node version, refactoring
2023-09-12 14:06:44 +02:00
4f86a4127c Merge pull request #51 from jkaninda/develop
Develop
2023-08-16 08:32:47 +02:00
e0ca7da470 Merge pull request #50 from jkaninda/develop
Add php 8.1 alpine version
2023-08-15 01:09:07 +02:00
7b49ffb01f Merge pull request #49 from jkaninda/develop
Develop
2023-08-12 08:58:27 +02:00
370238fa33 Merge pull request #47 from jkaninda/develop
Update README.md
2023-05-29 06:58:58 +02:00
fdd46315d7 Merge pull request #46 from jkaninda/develop
Update PHP Version
2023-05-29 01:37:19 +02:00
56d9701ff6 Merge pull request #45 from jkaninda/develop
Update PHP Version
2023-04-11 00:28:22 +02:00
3 changed files with 230 additions and 188 deletions

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Jonas Kaninda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

368
README.md
View File

@@ -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.
[![Build](https://github.com/jkaninda/laravel-php-fpm/actions/workflows/build.yml/badge.svg)](https://github.com/jkaninda/laravel-php-fpm/actions/workflows/build.yml)
[![Tests](https://github.com/jkaninda/laravel-php-fpm/actions/workflows/tests.yml/badge.svg)](https://github.com/jkaninda/laravel-php-fpm/actions/workflows/tests.yml)
![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/jkaninda/laravel-php-fpm?style=flat-square)
@@ -9,116 +14,76 @@
</a>
</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)
- [Github](https://github.com/jkaninda/laravel-php-fpm)
---
## **Supported PHP Versions**
- 8.4
- 8.3
- 8.2
- 8.1
- 8.0
- 7.4
- 7.2
## PHP Version:
- 8.4
- 8.3
- 8.2
- 8.1
- 8.0
- 7.4
- 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
## **Specifications**
## Simple docker-compose usage:
### **PHP Extensions**
- Composer
- OpenSSL
- XML
- PDO (MySQL and PostgreSQL)
- Rdkafka
- Redis
- Mbstring
- PCNTL
- ZIP
- GD
- BCMath
- Memcached
- Opcache
```yml
version: '3'
### **Additional Features**
- Laravel Cron Jobs
- Laravel Scheduler
- Supervisord
- Node.js and NPM
---
## **Getting Started**
### **Simple Docker-Compose Example**
```yaml
services:
php-fpm:
image: jkaninda/laravel-php-fpm:latest
container_name: php-fpm
restart: unless-stopped
user: www-data #Use www-data user for production usage
volumes:
#Project root
- ./src:/var/www/html
networks:
- default #if you're using networks between containers
```
## 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:
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
@@ -132,64 +97,64 @@ services:
- PHP_FPM_HOST=php-fpm:9000
networks:
- 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:
### docker-compose.yml
```yml
### **Basic Commands**
- **Start Containers**
```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:
php-fpm:
image: jkaninda/laravel-php-fpm
container_name: php-fpm
restart: unless-stopped
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
environment:
- APP_ENV=development # Optional, or production
#- LARAVEL_PROCS_NUMBER=1 # Optional, Laravel queue:work process number
#Nginx server
nginx-server:
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
@@ -198,46 +163,68 @@ services:
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
volumes:
storage-data:
```
## Docker run
```sh
docker compose up -d
### **Nginx Configuration (default.conf)**
```
## Build from base
```conf
server {
listen 80;
index index.php index.html;
root /var/www/html/public;
Dockerfile
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**
```Dockerfile
FROM jkaninda/laravel-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
# Run composer install / Optional
#RUN composer install
# Fix permissions
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.
### Example:
### **Adding Custom Supervisor Processes**
Place configurations in `/etc/supervisor/conf.d/`.
Example Kafka consumer process:
```conf
[program:kafkaconsume-worker]
process_name=%(program_name)s_%(process_num)02d
@@ -250,21 +237,26 @@ redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/kafka.log
```
### Custom php.ini
> /var/www/html/conf/php/php.ini
---
### Storage permision issue
```sh
docker compose exec php-fpm /bin/bash
```
## **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:
```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:
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! 😊

29
compose.yaml Normal file
View 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