If you are using docker-compose and the WORDPRESS_EXTRA_CONFIG
as I was, when I stumbled across that error, the solution would be to use double-dollar-sign notation as described in a corresponding issue in the docker-compose repo on GitHub.
This additional environment variable is described in the “How to use this image” of the official image documentation on hub.docker.com.
Your snippet in the context of a docker-compose.yml
would be:
wordpress:
image: wordpress:latest
environment:
WORDPRESS_CONFIG_EXTRA: |
define('FORCE_SSL_ADMIN', true);
if (strpos($${_SERVER}['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$${_SERVER}['HTTPS']='on';
of course extended with an appropriate database container and corresponding environment variables for database and user name and passwords.
This will result in the environment variable _SERVER
to only expand in the container. If you use a single dollar sign, docker-compose will try to populate the value of the specified environment variable from the surrounding context into the compose file as described in the official compose docs.