admin管理员组

文章数量:1295859

I followed this advice from the official docs to force SSL:

define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';

Wordpress runs in a docker container. When it starts it says

WARNING: The _SERVER variable is not set. Defaulting to a blank string.

And Wordpress' logs show this:

PHP Fatal error: Assignments can only happen to writable values in /var/www/html/wp-config.php

So _SERVER is the problem. How do I fix this?

I followed this advice from the official docs to force SSL:

define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';

Wordpress runs in a docker container. When it starts it says

WARNING: The _SERVER variable is not set. Defaulting to a blank string.

And Wordpress' logs show this:

PHP Fatal error: Assignments can only happen to writable values in /var/www/html/wp-config.php

So _SERVER is the problem. How do I fix this?

Share Improve this question asked Dec 5, 2019 at 11:00 lonixlonix 3011 silver badge10 bronze badges 1
  • Did you find a solution? – Jesus Iniesta Commented Nov 17, 2020 at 16:23
Add a comment  | 

1 Answer 1

Reset to default 2

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.

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.

本文标签: phpForce SSL using FORCESSLADMIN