From b1b8679fca71ead97b492cb0e1588740689edcae Mon Sep 17 00:00:00 2001 From: Father1993 Date: Fri, 3 Jul 2026 14:42:13 +1000 Subject: [PATCH] refactor(mysql,php): increase timeouts and optimize dev config --- README.md | 6 ++-- compose.yaml | 6 ++-- docker/mysql/Dockerfile | 5 +++ docker/mysql/my.cnf | 38 +++++++++++++++----- docker/nginx/templates/default.conf.template | 8 ++--- docker/php/php.ini | 4 +-- scripts/download-restore.sh | 11 ++++++ 7 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 docker/mysql/Dockerfile diff --git a/README.md b/README.md index 1364d4f..0b0458a 100644 --- a/README.md +++ b/README.md @@ -258,7 +258,7 @@ PHP limits in `docker/php/php.ini` (oriented toward large Bitrix backups). Timez - `memory_limit = 512M` - `upload_max_filesize = 1024M` - `post_max_size = 1024M` -- `max_execution_time = 300` +- `max_execution_time = 3600` nginx in `docker/nginx/templates/default.conf.template`: @@ -280,7 +280,7 @@ On first start with an empty volume, `docker/mysql/initdb/01-bitrix-user.sh`: - uses `mysql_native_password` when the plugin is available - falls back to the default MySQL authentication plugin otherwise -`docker/mysql/my.cnf` sets `utf8mb4`, increased `max_allowed_packet`, and Bitrix-friendly InnoDB options. +`docker/mysql/my.cnf` sets `utf8mb4` and a **dev-only** performance profile (fast bulk import, `innodb_flush_log_at_trx_commit=0`, `skip-log-bin`). Do not reuse these settings on production. ## Optional Extensions @@ -316,7 +316,7 @@ GitHub Actions workflow (`.github/workflows/ci.yml`) runs on push and pull reque | Domain does not open | Hosts file entry for `DOMAIN`; run `make doctor` | | SSL warning in browser | `mkcert -install`, then `make cert`, then `docker compose restart nginx` | | MySQL connection fails in restore wizard | Host must be `mysql`, not `localhost` | -| `make restore` — no archive found | Put `.tar.gz`, `.zip`, or other supported archive into `./www/` | +| Restore unpack is very slow or stalls | On Windows, keep the project inside WSL2 (`~/projects/...`), not on `C:\`. Then run `docker compose build php && docker compose restart` after config changes | | File permission issues on Linux/macOS | Set `UID` and `GID` in `.env` to output of `id -u` / `id -g` | | Shell scripts fail on Windows | Use Git Bash or WSL; ensure LF line endings (`.gitattributes`) | | PHP extension missing | Add it to `PHP_EXTRA_EXTENSIONS` and run `docker compose build php` | diff --git a/compose.yaml b/compose.yaml index b5a28dd..e645eec 100644 --- a/compose.yaml +++ b/compose.yaml @@ -51,7 +51,10 @@ services: start_period: 10s mysql: - image: ${MYSQL_IMAGE:-mysql:8.0.36} + build: + context: ./docker/mysql + args: + MYSQL_IMAGE: ${MYSQL_IMAGE:-mysql:8.0.36} container_name: ${PROJECT_NAME:-bitrix-local}-mysql restart: unless-stopped environment: @@ -68,7 +71,6 @@ services: start_period: 30s volumes: - mysql-data:/var/lib/mysql - - ./docker/mysql/my.cnf:/etc/mysql/conf.d/bitrix.cnf:ro - ./docker/mysql/initdb:/docker-entrypoint-initdb.d:ro volumes: diff --git a/docker/mysql/Dockerfile b/docker/mysql/Dockerfile new file mode 100644 index 0000000..6dc18c8 --- /dev/null +++ b/docker/mysql/Dockerfile @@ -0,0 +1,5 @@ +ARG MYSQL_IMAGE=mysql:8.0.36 +FROM ${MYSQL_IMAGE} + +COPY my.cnf /etc/mysql/conf.d/bitrix.cnf +RUN chmod 644 /etc/mysql/conf.d/bitrix.cnf diff --git a/docker/mysql/my.cnf b/docker/mysql/my.cnf index 849ca12..1268ba4 100644 --- a/docker/mysql/my.cnf +++ b/docker/mysql/my.cnf @@ -1,4 +1,6 @@ [mysqld] +default-authentication-plugin = mysql_native_password + character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init-connect = 'SET NAMES utf8mb4' @@ -6,17 +8,37 @@ init-connect = 'SET NAMES utf8mb4' sql_mode = "" innodb_strict_mode = OFF -max_allowed_packet = 512M -table_open_cache = 4096 -thread_cache_size = 64 -tmp_table_size = 256M -max_heap_table_size = 256M +# Memory +innodb_buffer_pool_size = 1G +innodb_buffer_pool_instances = 1 +innodb_log_file_size = 512M +innodb_log_buffer_size = 16M -innodb_buffer_pool_size = 512M -innodb_log_file_size = 256M -innodb_flush_log_at_trx_commit = 2 +# Speed (dev only — not for production) +innodb_flush_log_at_trx_commit = 0 innodb_flush_method = O_DIRECT +sync_binlog = 0 +skip-log-bin +performance_schema = OFF + +# Bitrix query buffers +join_buffer_size = 2M +sort_buffer_size = 4M +key_buffer_size = 256M +tmp_table_size = 128M +max_heap_table_size = 128M +max_allowed_packet = 128M + +# Cache +table_open_cache = 2048 +thread_cache_size = 8 +transaction-isolation = READ-COMMITTED + +# I/O +innodb_read_io_threads = 8 +innodb_write_io_threads = 8 +tmpdir = /tmp log_bin_trust_function_creators = 1 skip-name-resolve diff --git a/docker/nginx/templates/default.conf.template b/docker/nginx/templates/default.conf.template index 6829e8e..13b1e44 100644 --- a/docker/nginx/templates/default.conf.template +++ b/docker/nginx/templates/default.conf.template @@ -14,8 +14,8 @@ server { charset utf-8; client_max_body_size 1024M; - client_body_timeout 300s; - send_timeout 300s; + client_body_timeout 3600s; + send_timeout 3600s; ssl_certificate /etc/nginx/certs/${DOMAIN}.pem; ssl_certificate_key /etc/nginx/certs/${DOMAIN}-key.pem; @@ -59,8 +59,8 @@ server { fastcgi_pass php:9000; fastcgi_index index.php; - fastcgi_read_timeout 300s; - fastcgi_send_timeout 300s; + fastcgi_read_timeout 3600s; + fastcgi_send_timeout 3600s; fastcgi_buffer_size 128k; fastcgi_buffers 256 16k; fastcgi_busy_buffers_size 256k; diff --git a/docker/php/php.ini b/docker/php/php.ini index 50fcce5..a25e920 100644 --- a/docker/php/php.ini +++ b/docker/php/php.ini @@ -2,8 +2,8 @@ short_open_tag = On expose_php = Off memory_limit = 512M -max_execution_time = 300 -max_input_time = 300 +max_execution_time = 3600 +max_input_time = 3600 max_input_vars = 10000 post_max_size = 1024M diff --git a/scripts/download-restore.sh b/scripts/download-restore.sh index d6f9a4e..de69573 100644 --- a/scripts/download-restore.sh +++ b/scripts/download-restore.sh @@ -4,9 +4,19 @@ set -euo pipefail RESTORE_URL="https://www.1c-bitrix.ru/download/scripts/restore.php" RESTORE_FILE="www/restore.php" +patch_restore_php() { + if grep -q 'ini_get("max_execution_time")' "$RESTORE_FILE"; then + return 0 + fi + sed -i.bak 's/define("STEP_TIME", defined('\''VMBITRIX'\'') ? 30 : 15);/define("STEP_TIME", (int) ini_get("max_execution_time") ?: 3600);/' "$RESTORE_FILE" + rm -f "${RESTORE_FILE}.bak" + echo "Patched STEP_TIME in ${RESTORE_FILE}" +} + mkdir -p www if [ -s "$RESTORE_FILE" ]; then + patch_restore_php echo "restore.php already exists: ${RESTORE_FILE}" exit 0 fi @@ -22,4 +32,5 @@ else exit 1 fi +patch_restore_php echo "Downloaded: ${RESTORE_FILE}"