Private
Public Access
1
0

Fix WordPress unable to connect to database

Two bugs found:

1. wp-config-docker.php was being copied to /usr/src/wordpress/wp-config-docker.php,
   REPLACING the official WordPress config template. Our file only had security
   hardening settings (DISALLOW_FILE_EDIT, etc.) but no DB constants, auth keys,
   or table prefix. The generated wp-config.php had zero database configuration,
   so WordPress could never connect.

   Fix: Copy our config to /usr/src/websitebox-config.php instead, and load it
   via WORDPRESS_CONFIG_EXTRA=require_once in docker-compose.yml.

2. .user.ini set auto_prepend_file=wordfence-waf.php, but the file didn't exist
   until Wordfence plugin was installed. Every PHP request during initial setup
   returned a 500 fatal error.

   Fix: Add a stub wordfence-waf.php placeholder in the Docker image that gets
   copied with WordPress files. Wordfence replaces it during plugin activation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
constantprojects
2026-02-24 09:29:16 -07:00
parent 2c3b58eea7
commit 2e06db3291
2 changed files with 10 additions and 5 deletions

View File

@@ -22,8 +22,10 @@ RUN echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf
# Copy PHP upload config
COPY uploads.ini /usr/local/etc/php/conf.d/uploads.ini
# Copy wp-config template
COPY wp-config-docker.php /usr/src/wordpress/wp-config-docker.php
# Copy extra WordPress config (loaded via WORDPRESS_CONFIG_EXTRA)
# Do NOT overwrite /usr/src/wordpress/wp-config-docker.php — that's the official
# template that defines DB constants, auth keys, table prefix, etc.
COPY wp-config-docker.php /usr/src/websitebox-config.php
# Copy child theme and mu-plugins
COPY wp-content/themes/websitebox/ /usr/src/websitebox-theme/
@@ -33,9 +35,12 @@ COPY wp-content/mu-plugins/ /usr/src/websitebox-mu-plugins/
COPY entrypoint.sh /usr/local/bin/websitebox-entrypoint.sh
RUN chmod +x /usr/local/bin/websitebox-entrypoint.sh
# Create Wordfence-compatible .user.ini
# Create Wordfence-compatible .user.ini and stub WAF file
# The stub prevents PHP fatal errors before Wordfence is installed;
# Wordfence will overwrite it with the real WAF during plugin activation.
RUN echo "; Wordfence PHP settings" > /usr/src/wordpress/.user.ini && \
echo "auto_prepend_file = /var/www/html/wordfence-waf.php" >> /usr/src/wordpress/.user.ini
echo "auto_prepend_file = /var/www/html/wordfence-waf.php" >> /usr/src/wordpress/.user.ini && \
echo "<?php // Wordfence WAF placeholder - replaced during setup" > /usr/src/wordpress/wordfence-waf.php
ENTRYPOINT ["websitebox-entrypoint.sh"]
CMD ["php-fpm"]