Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Troubleshooting and HOWTOs

Anthony Fok edited this page Mar 30, 2022 · 11 revisions

Troubleshooting WordPress in Docker container

Avoid conflict with existing ports

  1. Edit .env and add WP_PORT=80 and DB_PORT=3306 in the .env as default.
  2. Edit docker-compose.yml and replace the host ports with ${WP_PORT} and ${DB_PORT} variables:
    Services:
      wordpress:
        ...
        ports:
          - ${IP}:${WP_PORT}:80
        ...
      db:
        ...
        ports:
          - ${IP}:${DB_PORT}:3306
        ...
  3. End users may then change .env to avoid conflict with existing web server and MySQL/MariaDB ports on their host machine.

Enter into the running WordPress container to diagnose problems

  1. Run docker compose up
  2. Run docker ps to list running containers, and find the container name riskprofiler-cms_wordpress_1
  3. Run docker exec -it riskprofiler-cms_wordpress_1 /bin/bash to enter the running WordPress container.

Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /var/www/html/site/wp-includes/wp-db.php on line 1653

Cause: wp-config.php provided upstream (e.g. HabitatSeven) is not configured for our Docker

Solution: Copy wp-config-docker.php to wp-app/site/wp-config.php, and maybe run fromdos or dos2unix to strip the trailing CR. No other change is required.

  • wp-config-docker.php may be found in the top-level directory of https://github.com/docker-library/wordpress, or in /usr/src/wordpress/wp-config-docker.php inside the wordpress Docker image.
  • wp-config-docker.php inherited the CRLF line-endings from wp-config-sample.php from WordPress.

Note: One can run docker exec -it riskprofiler-cms_wordpress_1 /bin/bash to examine /var/www/html/site/wp-includes/wp-db.php inside, though very few tools are available. Instead, with the volume mapping ./wp-app:/var/www/html defined in docker-compose.yml, we could just debug e.g. wp-app/site/wp-includes/wp-db.php from the host machine, and any code changes are reflected on the website immediately.

White screen (WSoD) Take #1

Symptom: The web page is rendered (actual HTML code returned), with <title> and all, but no actual content.

Cause (in our case): Missing theme files: wp-app/site/assets/themes/fw-parent is a git submodule which has not been fetched.

Solution: On OpenDRR/riskprofiler-cms, make sure both .gitmodules and wp-app/.gitmodules exist and point to the correct repos, and run git submodule update --init --recursive

What about built-in themes?

  • twentytwentytwo theme requires WordPress 5.9+ and is incompatible with WordPress 5.8.x that RiskProfiler.ca is currently using
  • twentytwentyone theme: cannot see the menu that leads to Scenarios, Risks etc.
  • twentytwenty theme works! The top menu actually show!

White screen (WSoD) Take #2

Still not working! 😢

Cause: The hostname is set to riskprofiler.demo (port 80) in the database dump provided by HabitatSeven, but I did not set these properly.

Workaround:

  1. Run sudo systemctl stop apache2 (on Linux), or stop your web server on port 80 using whatever means necessary.
  2. Run docker compose down -v where the -v must be used so that changes to the .env to actually take effect. (Cached copy somewhere? Not sure...)
  3. Edit .env and change WP_PORT=1380 to WP_PORT=80, and set IP=127.0.0.1 (in my case)
  4. Edit /etc/hosts and make sure there is something like 127.0.0.1 localhost riskprofiler.demo
  5. Run docker compose up
  6. Import database by running import-wp-db.sh (which runs source .env and mysql < wp_habitatseven_riskprofiler.sql)
  7. Visit http://riskprofiler.demo/

Better solution: Find a way to change the host name and port in WordPress (using WP-CLI, Phpmyadmin or mysql?)

Still not working! 😭

Let's try firing up WP-CLI for debugging...

How to get WP-CLI Docker to run?

See the wonderful answer by vstm at https://stackoverflow.com/a/51001043/3451096:

Edit docker-compose.yml and:

  1. Add user: xfs so the user ID in the wordpress:cli image matches that of www-data in the wordpress image.
  2. Add command: "sleep 1h" (or whatever command to keep the wpcli container up-and-running)

To test:

$ docker exec -it riskprofiler-cms_wpcli_1 /bin/bash
bash-5.1$ wp user list
+----+------------+--------------+--------------+--------------+---------------+
| ID | user_login | display_name | user_email   | user_registe | roles         |
|    |            |              |              | red          |               |
+----+------------+--------------+--------------+--------------+---------------+
| 1  | phil       | phil         | phil@example | 2021-10-20 1 | administrator |
|    |            |              | .com         | 3:23:53      |               |
+----+------------+--------------+--------------+--------------+---------------+

White screen (WSoD) Take #3

bash-5.1$ wp theme status
0 installed themes:

Legend: 
bash-5.1$ wp theme list
+------+--------+--------+---------+
| name | status | update | version |
+------+--------+--------+---------+
+------+--------+--------+---------+

Oh. Oh! I copied wp-config-docker.php to wp-config.php, but did not add HabitatSeven’s customization to it, namely:

define( 'WP_DEBUG_LOG', true );

$protocol = 'http';
if ( stripos ( $_SERVER['SERVER_PROTOCOL'], 'https' ) === 0 ) $protocol .= 's';

define ( 'WP_CONTENT_FOLDERNAME', 'assets' );
define ( 'WP_CONTENT_DIR', ABSPATH . WP_CONTENT_FOLDERNAME );
define ( 'WP_SITEURL', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/site/' );
define ( 'WP_CONTENT_URL', WP_SITEURL . WP_CONTENT_FOLDERNAME );

define ( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );

After:

bash-5.1$ wp theme status
2 installed themes:
  A fw-child  1.0
  P fw-parent 1.0

Legend: A = Active, P = Parent
bash-5.1$ wp theme list
+-----------+--------+--------+---------+
| name      | status | update | version |
+-----------+--------+--------+---------+
| fw-child  | active | none   | 1.0     |
| fw-parent | parent | none   | 1.0     |
+-----------+--------+--------+---------+

and... Hurray! http://riskprofiler.demo/ is working on my local machine!

Why is wp-app/wp-config.php generated when I run docker compose up?

Examining https://github.com/docker-library/wordpress, we see:

  1. In Dockerfile:
    COPY --chown=www-data:www-data wp-config-docker.php /usr/src/wordpress/
  2. docker-entrypoint.sh tries to find wp-config-docker.php in wp-app/, then /usr/src/wordpress/

How to log into Phpmyadmin?

  • Username: root (superuser account)
  • Password: Same as MYSQL_ROOT_PASSWORD, which is DB_ROOT_PASSWORD in .env because our docker-compose.yml says so.

See the "Credentials" and "Environment variables summary" sections on https://hub.docker.com/_/phpmyadmin for more information.

env_FILE mentioned in wp-config-docker.php?

Yes, putting something like wp-app/WORDPRESS_DB_HOST_FILE.txt with the content db inside, then adding #WORDPRESS_DB_HOST_FILE=WORDPRESS_DB_HOST_FILE.txt to .env, and setting environment in docker-docker.yml accordingly does work.

We probably won't need it, but in case we do:


Troubleshooting WordPress on bare metal

Tested on Debian GNU/Linux bookworm/sid in February 2022

Fatal error: Uncaught mysqli_sql_exception

Fatal error: Uncaught mysqli_sql_exception: No such file or directory in /srv/riskprofiler.ca/site/wp-includes/wp-db.php:1653 (Click to expand)

Fatal error: Uncaught mysqli_sql_exception: No such file or directory in /srv/riskprofiler.ca/site/wp-includes/wp-db.php:1653 Stack trace: #0 /srv/riskprofiler.ca/site/wp-includes/wp-db.php(1653): mysqli_real_connect() #1 /srv/riskprofiler.ca/site/wp-includes/wp-db.php(632): wpdb->db_connect() #2 /srv/riskprofiler.ca/site/wp-includes/load.php(558): wpdb->__construct() #3 /srv/riskprofiler.ca/site/wp-settings.php(124): require_wp_db() #4 /srv/riskprofiler.ca/site/wp-config.php(107): require_once('...') #5 /srv/riskprofiler.ca/site/wp-load.php(50): require_once('...') #6 /srv/riskprofiler.ca/site/wp-blog-header.php(13): require_once('...') #7 /srv/riskprofiler.ca/index.php(17): require('...') #8 {main} thrown in /srv/riskprofiler.ca/site/wp-includes/wp-db.php on line 1653

Solution: Set up MySQL or MariaDB properly.

Deprecation notices fill the page

PHP 8.1, which is what is in Debian sid as of February 2022, is too new for WordPress 5.8.x, and gives lots of deprecation notices on the rendered page:

Deprecation notices (Click to expand)

Deprecated: Return type of WP_Theme::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-theme.php on line 554

Deprecated: Return type of WP_Theme::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-theme.php on line 595

Deprecated: Return type of WP_Theme::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-theme.php on line 535

Deprecated: Return type of WP_Theme::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-theme.php on line 544

Deprecated: Return type of WP_REST_Request::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/rest-api/class-wp-rest-request.php on line 960

Deprecated: Return type of WP_REST_Request::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/rest-api/class-wp-rest-request.php on line 980

Deprecated: Return type of WP_REST_Request::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/rest-api/class-wp-rest-request.php on line 992

Deprecated: Return type of WP_REST_Request::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/rest-api/class-wp-rest-request.php on line 1003

Deprecated: Return type of WP_Block_List::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-block-list.php on line 151

Deprecated: Return type of WP_Block_List::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-block-list.php on line 175

Deprecated: Return type of WP_Block_List::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-block-list.php on line 164

Deprecated: Return type of WP_Block_List::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-block-list.php on line 186

Deprecated: Return type of WP_Block_List::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-block-list.php on line 138

Deprecated: Return type of WP_Block_List::offsetExists($index) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-block-list.php on line 75

Deprecated: Return type of WP_Block_List::offsetGet($index) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-block-list.php on line 89

Deprecated: Return type of WP_Block_List::offsetSet($index, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-block-list.php on line 110

Deprecated: Return type of WP_Block_List::offsetUnset($index) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-block-list.php on line 127

Deprecated: Return type of WP_Block_List::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/riskprofiler.ca/site/wp-includes/class-wp-block-list.php on line 199

Warning: session_start(): Session cannot be started after headers have already been sent in /srv/riskprofiler.ca/site/assets/themes/fw-parent/functions.php on line 165

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /srv/riskprofiler.ca/site/wp-includes/class-wp.php on line 173

Solution 1: Downgrade and pin to PHP 7.4 from Debian 11 (bullseye)

Add the following lines to /etc/apt/preferences:

Package: src:php-defaults
Pin: version 2:76
Pin-Priority: 1001

which allows us to downgrade php-common from 2:92 (requiring PHP 8.1) to 2:76 (requiring PHP 7.4), which allows us to downgrade from libapache2-mod-php8.1 to libapache2-mod-php7.4 accordingly.

Solution 2: Tweak PHP error reporting

Prepend

error_reporting(E_ALL ^ E_DEPRECATED);   

to site/wp-includes/class-wp-theme.php

Credit: wordpress - Turn off deprecated errors in PHP 5.3 - Stack Overflow

Solution 3: #[\ReturnTypeWillChange]

Add #[\ReturnTypeWillChange] attribute to the relevant class methods; see https://php.watch/versions/8.1/ReturnTypeWillChange

White screen (WSoD)

Symptom: The web page is rendered (actual HTML code returned), with <title> and all, but no actual content.

Cause (in our case): Missing theme files: site/assets/themes/fw-parent is a git submodule which wasn't loaded.

Solution: Make sure .gitmodules exists and points to the correct repo, and run git submodule update --init

What about built-in themes?

  • twentytwentytwo theme requires WordPress 5.9+ and is incompatible with WordPress 5.8.x that RiskProfiler.ca is currently using
  • twentytwentyone theme: cannot see the menu that leads to Scenarios, Risks etc.
  • twentytwenty theme works! The top menu actually show!

Not Found (404) error when accessing http://riskprofiler.demo/scenarios/

(but top-level http://riskprofiler.demo/ directory works)

  • Make sure Apache allows .htaccess ... AllowOverride All, and that the rewrite module is on: sudo a2enmod rewrite
Clone this wiki locally