From feed8797ae3e0e40501f30df32da3b6c4c3bc5eb Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Fri, 28 Nov 2025 02:44:40 +0800 Subject: [PATCH 1/8] DWDT-3-php-config-file - Update each php ini configuration base on the environment --- docker/containers/php/config/php-local.ini | 50 ++++++++++++++++---- docker/containers/php/config/php-prod.ini | 52 +++++++++++++++++---- docker/containers/php/config/php-test.ini | 53 ++++++++++++++++++---- 3 files changed, 129 insertions(+), 26 deletions(-) diff --git a/docker/containers/php/config/php-local.ini b/docker/containers/php/config/php-local.ini index aceaead..9350f20 100644 --- a/docker/containers/php/config/php-local.ini +++ b/docker/containers/php/config/php-local.ini @@ -1,21 +1,55 @@ ; -; Custom PHP Settings +; Custom PHP Settings for Local Development + +; ========================================================= +; 1. RESOURCE MANAGEMENT +; ========================================================= ; Maximum amount of memory a script may consume -memory_limit = 4096M +memory_limit = 512M + +; Maximum execution time of each script, in seconds +max_execution_time = 0 + + +; ========================================================= +; 2. ERROR & LOGGING +; ========================================================= -; Errors and Logs error_reporting = E_ALL -display_errors = On -log_errors = On +display_errors = On ; IMPORTANT: Show errors directly on the screen (Dev only) +log_errors = On ; Log errors to the specified file error_log = /var/log/php_errors.log -; Files & Uploads + +; ========================================================= +; 3. UPLOADS & FILES +; ========================================================= + post_max_size = 16M upload_max_filesize = 16M max_file_uploads = 20 -; Security + +; ========================================================= +; 4. SECURITY & SESSIONS +; ========================================================= + +; Ensures cookies are only sent over HTTPS +session.cookie_secure = 0 ; For Development, set to 0 and MUST be 1 in production. session.use_strict_mode = 1 session.use_only_cookies = 1 -session.cookie_secure = 1 + + +; ========================================================= +; 5. OPCACHE (PERFORMANCE) +; ========================================================= + +opcache.enable = 0 ; For Development, Opcache MUST be disabled +opcache.enable_cli = 0 ; Also disable for CLI commands like Composer +; The amount of memory to use for the opcode cache. 256MB is a good starting point. +; opcache.memory_consumption = 256 +; How often to check the timestamp of the PHP files for updates (0 = never check, ideal for immutable containers) +; opcache.validate_timestamps = 0 +; Cache the compiled PHP files even after the PHP-FPM process restarts. +; opcache.interned_strings_buffer = 16 diff --git a/docker/containers/php/config/php-prod.ini b/docker/containers/php/config/php-prod.ini index 3132d2c..8bde7f2 100644 --- a/docker/containers/php/config/php-prod.ini +++ b/docker/containers/php/config/php-prod.ini @@ -1,21 +1,55 @@ ; -; Custom PHP Settings +; Custom PHP Settings for Production -; Maximum amount of memory a script may consume -memory_limit = 4096M +; ========================================================= +; 1. RESOURCE MANAGEMENT +; ========================================================= + +; Maximum amount of memory a script may consume. +memory_limit = 256M + +; Maximum execution time of each script, in seconds +max_execution_time = 60 + + +; ========================================================= +; 2. ERROR & LOGGING +; ========================================================= -; Errors and Logs error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT -display_errors = Off -log_errors = On +display_errors = Off ; CRITICAL: Never show errors to the public +log_errors = On ; CRITICAL: Always log errors to the specified path error_log = /var/log/php_errors.log -; Files & Uploads + +; ========================================================= +; 3. UPLOADS & FILES +; ========================================================= + post_max_size = 16M upload_max_filesize = 16M max_file_uploads = 20 -; Security + +; ========================================================= +; 4. SECURITY & SESSIONS +; ========================================================= + +; Ensures cookies are only sent over HTTPS +session.cookie_secure = 1 session.use_strict_mode = 1 session.use_only_cookies = 1 -session.cookie_secure = 1 + + +; ========================================================= +; 5. OPCACHE (PERFORMANCE) +; ========================================================= + +opcache.enable = 1 +opcache.enable_cli = 1 +; The amount of memory to use for the opcode cache. 256MB is a good starting point. +opcache.memory_consumption = 256 +; How often to check the timestamp of the PHP files for updates (0 = never check, ideal for immutable containers) +opcache.validate_timestamps = 0 +; Cache the compiled PHP files even after the PHP-FPM process restarts. +opcache.interned_strings_buffer = 16 diff --git a/docker/containers/php/config/php-test.ini b/docker/containers/php/config/php-test.ini index aceaead..1ba341c 100644 --- a/docker/containers/php/config/php-test.ini +++ b/docker/containers/php/config/php-test.ini @@ -1,21 +1,56 @@ ; -; Custom PHP Settings +; Custom PHP Settings for Staging -; Maximum amount of memory a script may consume -memory_limit = 4096M +; ========================================================= +; 1. RESOURCE MANAGEMENT +; ========================================================= + +; Maximum amount of memory a script may consume. +memory_limit = 256M + +; Maximum execution time of each script, in seconds +max_execution_time = 60 + + +; ========================================================= +; 2. ERROR & LOGGING +; ========================================================= -; Errors and Logs error_reporting = E_ALL -display_errors = On -log_errors = On +display_errors = Off ; CRITICAL: Never show errors to the public +log_errors = On ; CRITICAL: Always log errors to the specified path error_log = /var/log/php_errors.log -; Files & Uploads + +; ========================================================= +; 3. UPLOADS & FILES +; ========================================================= + post_max_size = 16M upload_max_filesize = 16M max_file_uploads = 20 -; Security + +; ========================================================= +; 4. SECURITY & SESSIONS +; ========================================================= + +; Ensures cookies are only sent over HTTPS +session.cookie_secure = 1 session.use_strict_mode = 1 session.use_only_cookies = 1 -session.cookie_secure = 1 + + +; ========================================================= +; 5. OPCACHE (PERFORMANCE) +; ========================================================= + +; Opcache is the single most important performance setting for PHP +opcache.enable = 1 +opcache.enable_cli = 1 +; The amount of memory to use for the opcode cache. 256MB is a good starting point. +opcache.memory_consumption = 256 +; How often to check the timestamp of the PHP files for updates (0 = never check, ideal for immutable containers) +opcache.validate_timestamps = 0 +; Cache the compiled PHP files even after the PHP-FPM process restarts. +opcache.interned_strings_buffer = 16 From 4e85a4ed707e6967486abd7e6aa2a0e97bdab59e Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Fri, 28 Nov 2025 03:07:27 +0800 Subject: [PATCH 2/8] DWDT-3-mysql-config-file - Create a my.cnf file --- docker/containers/mysql/conf.d/my.cnf | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 docker/containers/mysql/conf.d/my.cnf diff --git a/docker/containers/mysql/conf.d/my.cnf b/docker/containers/mysql/conf.d/my.cnf new file mode 100644 index 0000000..a5b6ab0 --- /dev/null +++ b/docker/containers/mysql/conf.d/my.cnf @@ -0,0 +1,28 @@ +# Default MySQL Configuration (my.cnf) + +[mysqld] +# ========================================================= +# 1. CHARACTER SETTINGS +# Ensure full compatibility for modern web apps (supports emojis, etc.) +character-set-server = utf8mb4 +collation-server = utf8mb4_unicode_ci + +# ========================================================= +# 2. INNODB OPTIMIZATION +# Tuned for a typical development machine. +innodb_buffer_pool_size = 512M +innodb_log_file_size = 128M + +# ========================================================= +# 3. RESOURCE LIMITS +max_allowed_packet = 64M +max_connections = 500 + +# ========================================================= +# 4. STRICT MODE +# Enforce stricter SQL rules (highly recommended for development) +sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION" + +[client] +# Settings for MySQL client programs +default-character-set = utf8mb4 From f0d36bdc71815fa7b4fcdaa33c6223b2ae3e4709 Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Fri, 28 Nov 2025 04:33:04 +0800 Subject: [PATCH 3/8] DWDT-3-mysql-config-file - Update ReadMe files --- README.md | 6 ++++-- docker/README.md | 6 ++++-- docker/containers/README.md | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6638090..4e10485 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ my-project/ // Main Project Directory ├── docker/ // Docker Related │ ├── containers/ // Service Containers │ │ ├── nginx/ -│ │ │ ├── conf.d/ -│ │ │ │ └── default.conf // nginx config +│ │ │ ├── conf.d/ // NginX Configurations +│ │ │ │ └── default.conf // default configuration file │ │ │ └── Dockerfile │ │ ├── php/ │ │ │ ├── config/ // PHP Configurations @@ -21,6 +21,8 @@ my-project/ // Main Project Directory │ │ │ │ └── php-prod.ini // production specific configuration │ │ │ └── Dockerfile │ │ ├── mysql/ +│ │ │ ├── conf.d/ // MySql Configurations +│ │ │ │ └── my.cnf // default configuration file │ │ │ └── Dockerfile │ │ └── composer/ │ │ └── Dockerfile diff --git a/docker/README.md b/docker/README.md index 1103c54..8c879a7 100644 --- a/docker/README.md +++ b/docker/README.md @@ -9,8 +9,8 @@ my-project/ // Main Project Directory ├── docker/ // Docker Related │ ├── containers/ // Service Containers │ │ ├── nginx/ -│ │ │ ├── conf.d/ -│ │ │ │ └── default.conf // nginx config +│ │ │ ├── conf.d/ // NginX Configurations +│ │ │ │ └── default.conf // default configuration file │ │ │ └── Dockerfile │ │ ├── php/ │ │ │ ├── config/ // PHP Configurations @@ -19,6 +19,8 @@ my-project/ // Main Project Directory │ │ │ │ └── php-prod.ini // production specific configuration │ │ │ └── Dockerfile │ │ ├── mysql/ +│ │ │ ├── conf.d/ // MySql Configurations +│ │ │ │ └── my.cnf // default configuration file │ │ │ └── Dockerfile │ │ └── composer/ │ │ └── Dockerfile diff --git a/docker/containers/README.md b/docker/containers/README.md index 24ba45f..c9bcfaa 100644 --- a/docker/containers/README.md +++ b/docker/containers/README.md @@ -9,8 +9,8 @@ my-project/ // Main Project Directory ├── docker/ // Docker Related │ ├── containers/ // Service Containers │ │ ├── nginx/ -│ │ │ ├── conf.d/ -│ │ │ │ └── default.conf // nginx config +│ │ │ ├── conf.d/ // NginX Configurations +│ │ │ │ └── default.conf // default configuration file │ │ │ └── Dockerfile │ │ ├── php/ │ │ │ ├── config/ // PHP Configurations @@ -19,6 +19,8 @@ my-project/ // Main Project Directory │ │ │ │ └── php-prod.ini // production specific configuration │ │ │ └── Dockerfile │ │ ├── mysql/ +│ │ │ ├── conf.d/ // MySql Configurations +│ │ │ │ └── my.cnf // default configuration file │ │ │ └── Dockerfile │ │ └── composer/ │ │ └── Dockerfile From d236a394070433eaff3952fd4df316a59cb88217 Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Fri, 28 Nov 2025 07:36:22 +0800 Subject: [PATCH 4/8] DWDT-3-mysql-config-file - Fix ReadMe files typo --- README.md | 2 +- docker/README.md | 2 +- docker/environments/README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4e10485..42562d0 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ my-project/ // Main Project Directory │ │ │ └── Dockerfile │ │ └── composer/ │ │ └── Dockerfile -│ ├── enviroments/ // Environment variables +│ ├── environments/ // Environment variables │ │ ├── config.env // Main config file │ │ ├── local.env // Local development │ │ ├── test.env diff --git a/docker/README.md b/docker/README.md index 8c879a7..4cfb180 100644 --- a/docker/README.md +++ b/docker/README.md @@ -24,7 +24,7 @@ my-project/ // Main Project Directory │ │ │ └── Dockerfile │ │ └── composer/ │ │ └── Dockerfile -│ ├── enviroments/ // Environment variables +│ ├── environments/ // Environment variables │ │ ├── config.env // Main config file │ │ ├── local.env // Environment config file │ │ ├── test.env diff --git a/docker/environments/README.md b/docker/environments/README.md index bec119e..23d922d 100644 --- a/docker/environments/README.md +++ b/docker/environments/README.md @@ -8,7 +8,7 @@ my-project/ // Main Project Directory ├── docker/ // Docker Related │ ├── ... -│ ├── enviroments/ // Environment variables +│ ├── environments/ // Environment variables │ │ ├── config.env // Main config file │ │ ├── local.env // Local Database credentials or configs │ │ ├── test.env // Test/Staging Database credentials or configs From 95ffe39d12036e5e8cb06e4add10c3121306b522 Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Fri, 28 Nov 2025 09:31:09 +0800 Subject: [PATCH 5/8] DWDT-3-dockerfile-updates - Update Dockerfiles --- docker/containers/composer/Dockerfile | 18 ++++++++++++------ docker/containers/mysql/Dockerfile | 13 ++++++++++++- docker/containers/nginx/Dockerfile | 15 ++++++++++++--- docker/containers/php/Dockerfile | 17 ++++++++++++++--- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/docker/containers/composer/Dockerfile b/docker/containers/composer/Dockerfile index 272519b..0cb3a67 100644 --- a/docker/containers/composer/Dockerfile +++ b/docker/containers/composer/Dockerfile @@ -1,9 +1,12 @@ -# CRITICAL FIX: -# The FROM instruction now uses the alias 'base'. -# This alias is defined in docker-compose.yml's 'additional_contexts' -# and explicitly tells Docker to use the result of the 'php' service build -# as the base image, fixing the build order dependency. -FROM base +# ===================================================================== +# Composer Dockerfile +# --------------------------------------------------------------------- +# docker/containers/composer/Dockerfile +# ===================================================================== + +# Create composer image from the 'base' image alias defined in the docker-compose.yml +# 'additional_contexts' to point to the result of the PHP service build. +FROM base as composer_base # Install Composer # This curl command fetches the installer and pipes it to PHP, installing the @@ -13,3 +16,6 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local # Since the executable is in /usr/local/bin, it is automatically available in the container's PATH. # Add composer bin path to environment variable RUN export PATH=$PATH":/usr/bin" + +# Set working directory +WORKDIR /var/www/html diff --git a/docker/containers/mysql/Dockerfile b/docker/containers/mysql/Dockerfile index 03ca982..2af05d9 100644 --- a/docker/containers/mysql/Dockerfile +++ b/docker/containers/mysql/Dockerfile @@ -1,2 +1,13 @@ +#===================================================================== +# MySQL Dockerfile +#--------------------------------------------------------------------- +# docker/containers/mysql/Dockerfile +#===================================================================== + # Install MySQL -FROM library/mysql:5.7.22 +FROM mysql:5.7.22 + +# Copy MySQL configuration +COPY ./containers/mysql/conf.d/my.cnf /etc/mysql/conf.d/my.cnf + +EXPOSE 3306 diff --git a/docker/containers/nginx/Dockerfile b/docker/containers/nginx/Dockerfile index ceefa41..cc0aaf3 100644 --- a/docker/containers/nginx/Dockerfile +++ b/docker/containers/nginx/Dockerfile @@ -1,7 +1,16 @@ +#===================================================================== +# NginX Dockerfile +#--------------------------------------------------------------------- +# docker/containers/nginx/Dockerfile +#===================================================================== + # Install NginX -FROM library/nginx:stable-alpine +FROM nginx:stable-alpine -#WORKDIR ./var/www/html +# Set the working directory +WORKDIR /var/www/html # Copy NginX configuration -#COPY ./containers/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf +# This is crucial for making the built image self-contained and ready for production, +# even though the volume mount in docker-compose.yml will override it for local development. +COPY ./containers/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf diff --git a/docker/containers/php/Dockerfile b/docker/containers/php/Dockerfile index 8e1bdc1..ffa76ef 100644 --- a/docker/containers/php/Dockerfile +++ b/docker/containers/php/Dockerfile @@ -1,6 +1,15 @@ -# Start from the official base image +#===================================================================== +# PHP Dockerfile +#--------------------------------------------------------------------- +# docker/containers/php/Dockerfile +#===================================================================== + +# Install PHP FROM php:8.2-fpm-alpine +# 1. Define the build argument for the environment +ARG SYS_ENV + # Set the working directory to the standard web root WORKDIR /var/www/html @@ -9,11 +18,13 @@ WORKDIR /var/www/html # 2. Configure and install required PHP extensions (opcache for speed) RUN apk add --no-cache git zip libzip-dev \ && docker-php-ext-configure zip \ - && docker-php-ext-install mysqli pdo pdo_mysql opcache zip \ + && docker-php-ext-install pdo pdo_mysql opcache zip \ && rm -rf /var/cache/apk/* # Clean up cache to minimize image size # Copy PHP configuration -# COPY ./containers/php/config/php-$SYS_ENV.ini /usr/local/etc/php/php.ini +# This uses the build arg to select the correct INI file (e.g., php-development.ini) +# and places it in the conf.d directory as 99-custom.ini to ensure it overrides defaults. +COPY ./containers/php/config/php-${SYS_ENV}.ini /usr/local/etc/php/conf.d/99-custom.ini # Default command to start PHP-FPM CMD ["php-fpm"] \ No newline at end of file From d0c4c78c868900b046919efbf502dc16b39ec2c0 Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Fri, 28 Nov 2025 09:31:37 +0800 Subject: [PATCH 6/8] DWDT-3-dockerfile-updates - Update docker compose --- docker/docker-compose.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index c5b4bcb..9335030 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -26,8 +26,8 @@ services: ports: - "80:80" volumes: - - "${PATH_CONFIGS_NGINX}:/etc/nginx/conf.d/default.conf" - - "${PATH_VOLUMES_LOGS}/nginx:/var/log/nginx" + - "${PATH_CONTAINERS}/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf" + - "${PATH_VOLUMES}/logs/nginx:/var/log/nginx" - "${PATH_SOURCE_LOCAL}:${PATH_SOURCE_LIVE}" # Vendor volume overlay - vendor_data:/var/www/html/vendor @@ -47,12 +47,14 @@ services: build: context: . dockerfile: containers/php/Dockerfile + args: + SYS_ENV: "${SYS_ENV}" image: php:php-8.2-fpm-alpine ports: - "9000:9000" volumes: - - "${PATH_CONFIGS_PHP}:/usr/local/etc/php/php.ini" - - "${PATH_VOLUMES_LOGS}/php:/var/log/php_errors.log" + - "${PATH_CONTAINERS}/php/config/php-${SYS_ENV}.ini:/usr/local/etc/php/php.ini" + - "${PATH_VOLUMES}/logs/php:/var/log/php_errors.log" - "${PATH_SOURCE_LOCAL}:${PATH_SOURCE_LIVE}" # +----------------------+ # @@ -75,7 +77,7 @@ services: env_file: - "${PATH_ENVIRONMENTS}/${SYS_ENV}.env" volumes: - - "${PATH_VOLUMES_DATABASE}:/var/lib/mysql" + - "${PATH_VOLUMES}/${DB_DRIVER}/${DB_DRIVER}_${DB_VERSION}:/var/lib/mysql" environment: SERVICE_TAGS: dev SERVICE_NAME: mysql @@ -103,7 +105,7 @@ services: image: composer:composer-2.6.1 working_dir: /var/www/html volumes: - - "${PATH_CONFIGS_PHP}:/usr/local/etc/php/php.ini" + - "${PATH_CONTAINERS}/php/config/php-${SYS_ENV}.ini:/usr/local/etc/php/php.ini" - "${PATH_SOURCE_LOCAL}:${PATH_SOURCE_LIVE}" # CRITICAL: Composer installs dependencies directly into this fast volume - vendor_data:/var/www/html/vendor From 358779639705fd478f543194f1afe643bf6195c4 Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Fri, 28 Nov 2025 09:33:11 +0800 Subject: [PATCH 7/8] DWDT-3-dockerfile-updates - Update config comment unused variables --- docker/environments/config.env | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/environments/config.env b/docker/environments/config.env index 16bf5a8..ed48d49 100644 --- a/docker/environments/config.env +++ b/docker/environments/config.env @@ -18,11 +18,11 @@ DB_PORT=3306 DB_VERSION=5.7.22 # SOURCE / VOLUMES -PATH_VOLUMES_DATABASE=${PATH_VOLUMES}/${DB_DRIVER}/${DB_DRIVER}_${DB_VERSION} -PATH_VOLUMES_LOGS=${PATH_VOLUMES}/logs +#PATH_VOLUMES_DATABASE=${PATH_VOLUMES}/${DB_DRIVER}/${DB_DRIVER}_${DB_VERSION} +#PATH_VOLUMES_LOGS=${PATH_VOLUMES}/logs PATH_SOURCE_LIVE=/var/www/html PATH_SOURCE_LOCAL=../src # CONFIGS -PATH_CONFIGS_NGINX=${PATH_CONTAINERS}/nginx/conf.d/default.conf -PATH_CONFIGS_PHP=${PATH_CONTAINERS}/php/config/php-${SYS_ENV}.ini +#PATH_CONFIGS_NGINX=${PATH_CONTAINERS}/nginx/conf.d/default.conf +#PATH_CONFIGS_PHP=${PATH_CONTAINERS}/php/config/php-${SYS_ENV}.ini From 3eb3a9f02224be487b4fa65932cffd82059fe50e Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Fri, 28 Nov 2025 09:36:26 +0800 Subject: [PATCH 8/8] DWDT-3-dockerfile-updates - Update Dockerfiles --- docker/containers/php/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/containers/php/Dockerfile b/docker/containers/php/Dockerfile index ffa76ef..8542c40 100644 --- a/docker/containers/php/Dockerfile +++ b/docker/containers/php/Dockerfile @@ -27,4 +27,4 @@ RUN apk add --no-cache git zip libzip-dev \ COPY ./containers/php/config/php-${SYS_ENV}.ini /usr/local/etc/php/conf.d/99-custom.ini # Default command to start PHP-FPM -CMD ["php-fpm"] \ No newline at end of file +CMD ["php-fpm"]