Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress with Docker-compose not getting environment variables

The docker-compose file contains standard wordpress settings. DB and nginx service blocks are left out for brevity.

  image: wordpress:6.1.1-php8.2-fpm
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: user
      WORDPRESS_DB_PASSWORD: password
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_WP_HOME: http://example.com
      WORDPRESS_CONFIG_EXTRA: >
          define('WP_HOME', 'http://example.com/');
          define('WP_SITEURL', 'http://example.com/');
          define('FORCE_SSL_ADMIN', false);
    volumes:
      - wp-app:/var/www/html
    depends_on:
      - db
    networks:
      - wordpress-network

I expected the variables WP_HOME WP_SITEURL and FORCE_SSL_ADMIN to be set in /var/www/html/wp-config.php inside the container. But the values there are just the default values or blank. Maybe these user variables get set somewhere else. But trying to locate them by grep-ing the wordpress installation directory did not return any hits of the specific URL.

I tried different syntax like:

WORDPRESS_CONFIG_EXTRA=
    define('WP_HOME', 'http://example.com/');

or

WORDPRESS_CONFIG_EXTRA: >
          define('WP_HOME', 'http://example.com/');

but still no success. What is the correct way to add these environment variables to my wordpress setup?

like image 949
theDrifter Avatar asked Sep 16 '26 22:09

theDrifter


1 Answers

The wp-config.php file is no longer written to, rather its created at runtime (reference)

The variables are not embedded into the file anymore -- they get loaded at runtime instead so that changes are applied correctly without any hacky file editing.

This is handy to see what env vars docker is using: docker exec <name> printenv

like image 131
Seba Illingworth Avatar answered Sep 18 '26 13:09

Seba Illingworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!