Skip to content

Commit

Permalink
chore: redirect php-fpm process to supervisor's log, refactoring of code
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaninda committed Jan 13, 2024
1 parent 9fa8b63 commit 2f274a7
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 31 deletions.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,15 @@ services:
## Laravel `artisan` command usage:
### Open php-fpm
```sh
docker-compose exec php-fpm /bin/bash
docker compose exec php-fpm /bin/bash

```

Default web root:
```
/var/www/html
```
## Configurations

### Laravel migration
```sh
php atisan migrate
- Superfisor 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
Expand Down Expand Up @@ -192,6 +187,7 @@ volumes:

```
## Build from base

Dockerfile
```Dockerfile
FROM jkaninda/laravel-php-fpm:8.3
Expand All @@ -212,7 +208,8 @@ RUN chown -R www-data:www-data /var/www/html
```
## Supervisord
### Add supervisor process in
> /var/www/html/conf/worker/supervisor.conf

> /etc/supervisor/conf.d/
In case you want to execute and maintain a task or process with supervisor.

Expand All @@ -235,7 +232,7 @@ stdout_logfile=/var/www/html/storage/logs/kafka.log
### Storage permision issue
```sh
docker-compose exec php-fpm /bin/bash
docker compose exec php-fpm /bin/bash
```

```sh
Expand Down
3 changes: 2 additions & 1 deletion src/docker/7.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ RUN groupmod -g ${USER_ID} ${GROUP_NAME}
RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /tmp

EXPOSE 9000
CMD [ "entrypoint" ]
3 changes: 2 additions & 1 deletion src/docker/7.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ RUN groupmod -g ${USER_ID} ${GROUP_NAME}
RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /tmp

EXPOSE 9000
CMD [ "entrypoint" ]
3 changes: 2 additions & 1 deletion src/docker/7.4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ RUN groupmod -g ${USER_ID} ${GROUP_NAME}
RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /tmp

EXPOSE 9000
CMD [ "entrypoint" ]
3 changes: 2 additions & 1 deletion src/docker/8.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ RUN groupmod -g ${USER_ID} ${GROUP_NAME}
RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /tmp

EXPOSE 9000
CMD [ "entrypoint" ]
3 changes: 2 additions & 1 deletion src/docker/8.1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ RUN groupmod -g ${USER_ID} ${GROUP_NAME}
RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /tmp

EXPOSE 9000
CMD [ "entrypoint" ]
3 changes: 2 additions & 1 deletion src/docker/8.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ RUN groupmod -g ${USER_ID} ${GROUP_NAME}
RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /tmp

EXPOSE 9000
CMD [ "entrypoint" ]
3 changes: 2 additions & 1 deletion src/docker/8.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ RUN groupmod -g ${USER_ID} ${GROUP_NAME}
RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ && \
chown -R ${USER_NAME}:${GROUP_NAME} /tmp

EXPOSE 9000
CMD [ "entrypoint" ]
10 changes: 0 additions & 10 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ else
info "artisan file not found"
fi

## Check if the supervisor config file exists
if [ -f /var/www/html/conf/worker/supervisor.conf ]; then
info "additional supervisor config found"
cp /var/www/html/conf/worker/supervisor.conf /etc/supervisor/conf.d/supervisor.conf
else
info "Supervisor.conf not found"
info "If you want to add more supervisor configs, create config file in /var/www/html/conf/worker/supervisor.conf"
info "Start supervisor with default config..."
fi
## Check if php.ini file exists
if [ -f /var/www/html/conf/php/php.ini ]; then
cp /var/www/html/conf/php/php.ini $PHP_INI_DIR/conf.d/
Expand All @@ -70,4 +61,3 @@ else
fi

supervisord -c /etc/supervisor/supervisord.conf
#exec "$@"
10 changes: 7 additions & 3 deletions src/supervisor/supervisord.conf
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
[supervisord]
nodaemon=true
#user=root
user=%(ENV_USER_NAME)s
logfile=/var/log/supervisor/supervisord.log
logfile_maxbytes = 50MB
pidfile=/tmp/supervisord.pid
directory = /tmp

[program:php-fpm]
command=/usr/local/sbin/php-fpm
numprocs=1
autostart=true
autorestart=true
stderr_logfile=/var/log/php-fpm_consumer.err.log
stdout_logfile=/var/log/php-fpm_consumer.out.log
redirect_stderr=true
stdout_logfile=/dev/stdout
stderr_logfile=/dev/stdout
stdout_logfile_maxbytes=0
user=www-data
priority=1

Expand Down

0 comments on commit 2f274a7

Please sign in to comment.