From 7e956cc02eb9dd6eb7cbf3864d031ab66aad52bb Mon Sep 17 00:00:00 2001 From: z0rayy Date: Wed, 10 Jun 2026 17:11:13 +0700 Subject: [PATCH] Dockerize: Add Dockerfile, nginx.conf, supervisord.conf with clear_env=no fix --- .dockerignore | 7 +++++++ Dockerfile | 40 ++++++++++++++++++++++++++++++++++++++++ nginx.conf | 46 ++++++++++++++++++++++++++++++++++++++++++++++ php-fpm.conf | 5 +++++ supervisord.conf | 22 ++++++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 nginx.conf create mode 100644 php-fpm.conf create mode 100644 supervisord.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..36549f0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.gitignore +node_modules +*.log +.env +.env.local +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0c89b10 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# ========================================================= +# Dockerfile - WebGIS PHP Application +# Uses Nginx + PHP-FPM in a single Alpine-based container +# ========================================================= + +FROM php:8.2-fpm-alpine + +# Install system dependencies and PHP extensions +RUN apk add --no-cache \ + nginx \ + supervisor \ + && docker-php-ext-install mysqli pdo pdo_mysql \ + && docker-php-ext-enable mysqli pdo_mysql + +# Copy Nginx configuration +COPY nginx.conf /etc/nginx/nginx.conf + +# Copy supervisor configuration (runs Nginx + PHP-FPM together) +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +# CRITICAL: Allow ENV vars (DB_HOST, DB_PASS etc) from Coolify to be +# readable by PHP's getenv(). By default PHP-FPM clears all env vars. +RUN echo "[www]" >> /usr/local/etc/php-fpm.d/www.conf && \ + echo "clear_env = no" >> /usr/local/etc/php-fpm.d/www.conf + +# Set working directory +WORKDIR /var/www/html + +# Copy all application files +COPY . . + +# Set correct permissions for web files +RUN chown -R www-data:www-data /var/www/html \ + && chmod -R 755 /var/www/html + +# Expose port 80 +EXPOSE 80 + +# Start supervisor (which manages both Nginx and PHP-FPM) +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..6934c72 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,46 @@ +worker_processes auto; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + sendfile on; + keepalive_timeout 65; + + server { + listen 80; + server_name _; + root /var/www/html; + index index.php index.html; + + # Main location block + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + # PHP-FPM handler - all .php files are processed by PHP-FPM + location ~ \.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; + } + + # Allow access to static files (HTML, CSS, JS, images) + location ~* \.(html|css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$ { + expires max; + access_log off; + } + + # Security: deny access to hidden files + location ~ /\. { + deny all; + } + } +} diff --git a/php-fpm.conf b/php-fpm.conf new file mode 100644 index 0000000..deeca4f --- /dev/null +++ b/php-fpm.conf @@ -0,0 +1,5 @@ +# PHP-FPM environment variable passthrough +# This ensures ENV vars from Coolify are accessible via getenv() in PHP + +; Clear all environment variables (security) +clear_env = no diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 0000000..cc1d026 --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,22 @@ +[supervisord] +nodaemon=true +logfile=/var/log/supervisord.log +pidfile=/var/run/supervisord.pid + +[program:nginx] +command=nginx -g "daemon off;" +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:php-fpm] +command=php-fpm -F +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0