Completing WordPress Health Check inside Docker

Missing Modules

It is very tempting to simply use the official WordPress Docker image. However, new feature HEALH CHECK in 5.X – you will observe a recommendation – something like following:

Missing Modules in WordPress Docker

To sum up – bcmath, exif and imagick are not installed in wordpress docker image by default.

Resolution

The same way we added Imagick in PHP Docker, You can create your own Dockerfile instead of using image directly as following:

FROM wordpress:5.2.0-php7.3-apache
# Better WordPress Health-Check
# Install Imagick
RUN apt-get update && apt-get install -y libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN printf "\n" | pecl install imagick
RUN docker-php-ext-enable imagick
# Install bcmath and exif
RUN docker-php-ext-install bcmath exif

Great Job! Everything is running smoothly here.

Passing Real IP in WordPress behind Proxy or in Docker

If you have followed the tutorial on How to run WordPress Blog behind Nginx Secure (https) Proxy, you might be under a situation that WordPress is showing all ips as proxy ips. In case of Docker it must be like 172.X.X.X otherwise, it is the ip of your server. 

If this is a problem?

You might be wondering if this is worth solving? Well Yes!, Most of the real comments were categorized as spam. 

Adding Real-IP to WordPress

Step 1 – Editing WordPress config

In wp-config.php file add following lines just above /* That’s all, stop editing! Happy blogging. */

// Use X-Forwarded-For HTTP Header to Get Visitor's Real IP Address
if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
  $http_x_headers = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
  $_SERVER['REMOTE_ADDR'] = $http_x_headers[0];
}
/* That's all, stop editing! Happy blogging. */

Step 2 – Editing Nginx

Inside your proxy settings in nginx, simply add this:

proxy_set_header        X-Real-IP       $remote_addr;

In case of WordPress Behind Docker

In case if you are using Docker, you will need to copy wp-config.php from container and later copy to container. This can be done as following.

#Copy from docker container
docker cp project_wordpress_1:/var/www/html/wp-config.php .

#Copy to docker container
docker cp wp-config.php project_wordpress_1:/var/www/html/wp-config.php

Easy-peasy right?

How to run WordPress Blog behind Nginx Secure (https) Proxy

When I started this blog, I was asked, what was the most annoying thing I get while setup up a WordPress blog. I can’t really get SSL thing out of my head – yet. It was totally worth it.

When running a WordPress behind a proxy, it will give an error of unable to complete the request.

There are kinds of problem you will see:

  1. WordPress homepage is stuck in an endless loop.
  2. CSS/JS files are not loading.
  3. Transport error.

Solution:

Editing Nginx for WordPress behind Proxy

Add following proxy configuration in your Nginx

proxy_set_header X-Forwarded-Proto https;

Your nginx configuration should look more or less like:

    location / {
        try_files $uri @app;
    }
    location @app {
        proxy_set_header X-Forwarded-Proto https;
        proxy_pass http://127.0.0.1:8888;
        include .common/proxy.common;
    }

Config for SSL enabled WordPress behind Proxy

There is a possibility that you might need to add the following as well in wp-config.php file in some versions of WordPress.

if($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){

    $_SERVER['HTTPS'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}

Do you have wp-config.php inside Docker?

If your wp-config.php file is under Docker, then you can use docker cp command to copy/copy back file.

#Copy from docker container
docker cp project_wordpress_1:/var/www/html/wp-config.php .

#Copy to docker container
docker cp wp-config.php project_wordpress_1:/var/www/html/wp-config.php