mirror of
https://github.com/jkaninda/nginx-php-fpm.git
synced 2025-12-06 21:49:41 +01:00
Refactoring
This commit is contained in:
13
Dockerfile
13
Dockerfile
@@ -1,8 +1,7 @@
|
||||
FROM php:8.1-fpm
|
||||
ENV WORKDIR=/var/www/html
|
||||
ENV STORAGE_DIR=${WORKDIR}/storage
|
||||
FROM php:8.1.7-fpm
|
||||
ARG WORKDIR=/var/www/html
|
||||
ENV DOCUMENT_ROOT=${WORKDIR}
|
||||
ENV LARAVEL_PROCS_NUMBER=2
|
||||
ENV LARAVEL_PROCS_NUMBER=1
|
||||
ENV DOMAIN=_
|
||||
ENV CLIENT_MAX_BODY_SIZE=15M
|
||||
# Install system dependencies
|
||||
@@ -71,13 +70,13 @@ RUN composer global require "laravel/envoy=~1.0"
|
||||
# Set working directory
|
||||
WORKDIR $WORKDIR
|
||||
|
||||
# nginx site conf
|
||||
RUN rm -Rf /var/www/* && \
|
||||
mkdir /var/www/html/
|
||||
mkdir -p /var/www/html
|
||||
|
||||
ADD src/index.php $WORKDIR/index.php
|
||||
ADD src/conf/nginx/default.conf /etc/nginx/sites-available/default
|
||||
ADD src/php.ini $PHP_INI_DIR/conf.d/
|
||||
ADD src/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
|
||||
COPY ./entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
@@ -93,4 +92,6 @@ RUN groupmod -g 1000 www-data
|
||||
RUN chmod -R 755 $WORKDIR
|
||||
RUN chown -R www-data:www-data $WORKDIR
|
||||
EXPOSE 9000
|
||||
EXPOSE 80
|
||||
CMD [ "entrypoint" ]
|
||||
|
||||
|
||||
22
README.md
22
README.md
@@ -50,13 +50,11 @@ services:
|
||||
## Laravel `artisan` command usage:
|
||||
### CLI
|
||||
```sh
|
||||
docker-compose exec app bash
|
||||
docker-compose exec app bash
|
||||
|
||||
```
|
||||
|
||||
### Laravel migration
|
||||
```sh
|
||||
php atisan migrate
|
||||
docker exec -it app bash
|
||||
|
||||
```
|
||||
|
||||
@@ -67,8 +65,7 @@ version: '3'
|
||||
services:
|
||||
app:
|
||||
image: jkaninda/nginx-php-fpm
|
||||
container_name: my-app
|
||||
working_dir: /var/www/html #Optional, If you want to use a custom directory
|
||||
container_name: nginx-fpm
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "80:80"
|
||||
@@ -76,15 +73,14 @@ services:
|
||||
#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
|
||||
- storage-data:/var/www/html/storage/app #Optional, your custom storage data
|
||||
#./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=3 # Optional, Laravel queue:work process number
|
||||
- CLIENT_MAX_BODY_SIZE=20M # Optional
|
||||
- DOMAIN=example.com # Optional
|
||||
volumes:
|
||||
storage-data:
|
||||
- LARAVEL_PROCS_NUMBER=2 # Optional, Laravel queue:work process number
|
||||
#- CLIENT_MAX_BODY_SIZE=20M # Optional
|
||||
#- DOMAIN=example.com # Optional
|
||||
#- DOCUMENT_ROOT=/var/www/html Optional
|
||||
|
||||
```
|
||||
|
||||
## Docker run
|
||||
|
||||
@@ -8,25 +8,11 @@ echo "***********************************************************"
|
||||
|
||||
set -e
|
||||
|
||||
## Create PHP-FPM worker process
|
||||
TASK=/etc/supervisor/conf.d/php-fpm.conf
|
||||
touch $TASK
|
||||
cat > "$TASK" <<EOF
|
||||
[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
|
||||
user=root
|
||||
priority=100
|
||||
EOF
|
||||
## Check if the artisan file exists
|
||||
if [ -f $WORKDIR/artisan ]; then
|
||||
if [ -f /var/www/html/artisan ]; then
|
||||
echo "${Green} artisan file found, creating laravel supervisor config"
|
||||
# Set DocumentRoot to the Laravel project directory
|
||||
export DOCUMENT_ROOT=$WORKDIR/public
|
||||
export DOCUMENT_ROOT=/var/www/html/public
|
||||
##Create Laravel Scheduler process
|
||||
TASK=/etc/supervisor/conf.d/laravel-worker.conf
|
||||
touch $TASK
|
||||
@@ -36,7 +22,7 @@ if [ -f $WORKDIR/artisan ]; then
|
||||
user=root
|
||||
[program:Laravel-scheduler]
|
||||
process_name=%(program_name)s_%(process_num)02d
|
||||
command=/bin/sh -c "while [ true ]; do (php $WORKDIR/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
|
||||
@@ -46,7 +32,7 @@ if [ -f $WORKDIR/artisan ]; then
|
||||
|
||||
[program:Laravel-worker]
|
||||
process_name=%(program_name)s_%(process_num)02d
|
||||
command=php $WORKDIR/artisan queue:work --sleep=3 --tries=3
|
||||
command=php /var/www/html/artisan queue:work --sleep=3 --tries=3
|
||||
autostart=true
|
||||
autorestart=true
|
||||
numprocs=$LARAVEL_PROCS_NUMBER
|
||||
@@ -58,17 +44,6 @@ echo "${Green} Laravel supervisor config created"
|
||||
else
|
||||
echo "${Red} artisan file not found"
|
||||
fi
|
||||
#check if storage directory exists
|
||||
echo "Checking if storage directory exists"
|
||||
if [ -d "$STORAGE_DIR" ]; then
|
||||
echo "Directory $STORAGE_DIR exist. Fixing permissions..."
|
||||
chown -R www-data:www-data $STORAGE_DIR
|
||||
chmod -R 775 $STORAGE_DIR
|
||||
echo "${Green}Permissions fixed"
|
||||
|
||||
else
|
||||
echo "${Red} Directory $STORAGE_DIR does not exist"
|
||||
fi
|
||||
|
||||
# Enable custom nginx config files if they exist
|
||||
if [ -f /var/www/html/conf/nginx/nginx.conf ]; then
|
||||
@@ -94,7 +69,8 @@ if [ -f /var/www/html/conf/nginx/nginx-site.conf ]; then
|
||||
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; error_log /var/log/nginx/error.log;
|
||||
index index.php index.html index.htm index.nginx-debian.html;
|
||||
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
|
||||
@@ -146,19 +122,8 @@ if [ -f /var/www/html/conf/worker/supervisor.conf ]; then
|
||||
echo "${Green} If you want to add more supervisor configs, create config file in /var/www/html/conf/worker/supervisor.conf"
|
||||
echo "${Green} Start supervisor with default config..."
|
||||
fi
|
||||
## Add nginx process to supervisor
|
||||
TASK=/etc/supervisor/conf.d/nginx.conf
|
||||
touch $TASK
|
||||
cat > "$TASK" <<EOF
|
||||
[program:nginx]
|
||||
command=/usr/sbin/nginx -g "daemon off;"
|
||||
numprocs=1
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stderr_logfile=/var/log/ngnix.err.log
|
||||
stdout_logfile=/var/log/ngnix.out.log
|
||||
user=root
|
||||
EOF
|
||||
|
||||
|
||||
|
||||
echo ""
|
||||
echo "**********************************"
|
||||
|
||||
@@ -6,7 +6,7 @@ server {
|
||||
# Add index.php to setup Nginx, PHP & PHP-FPM config
|
||||
index index.php index.html index.htm index.nginx-debian.html; error_log /var/log/nginx/error.log;
|
||||
access_log /var/log/nginx/access.log;
|
||||
root /var/www/html/public;
|
||||
root /var/www/html;
|
||||
# pass PHP scripts on Nginx to FastCGI (PHP-FPM) server
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
|
||||
27
src/supervisor/supervisord.conf
Normal file
27
src/supervisor/supervisord.conf
Normal file
@@ -0,0 +1,27 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
user=root
|
||||
|
||||
|
||||
[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
|
||||
user=root
|
||||
priority=100
|
||||
|
||||
[program:nginx]
|
||||
command=/usr/sbin/nginx -g "daemon off;"
|
||||
numprocs=1
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stderr_logfile=/var/log/ngnix.err.log
|
||||
stdout_logfile=/var/log/ngnix.out.log
|
||||
user=root
|
||||
priority=100
|
||||
|
||||
[include]
|
||||
files = /etc/supervisor/conf.d/*.conf
|
||||
Reference in New Issue
Block a user