Skip to content

Storing a lot of environment variables #4969

Open

Description

@szepeviktor

It seems to be wp-cli.yml cannot hold envs.
We use a WP installation depending on many envs.
Now I keep putenv()-s in

require:
  - /home/user/website/wp-cli-envs.php

Could we implement this?

env:
  DB_NAME: "instahuu"

Activity

  1. schlessera commented on Oct 24, 2018

    @schlessera
    Member

    I don't necessarily dislike the idea, but I think this might be outside of the scope of WP-CLI.

    Why are your environment variables not part of your normal WP bootstrap, if they are needed? Is there a specific reason why this type of setup couldn't just be part of your actual project, instead of coded into WP-CLI?

  2. szepeviktor commented on Oct 24, 2018

    @szepeviktor
    ContributorAuthor

    We use a skeleton (without actual values) wp-config with 20+ env-s.

    Something like https://m.dotdev.co/secure-your-wordpress-config-with-dotenv-d939fcb06e24

    In PHP-FPM envs are in the pool config file. When running on CLI I need a WP-CLi-integrated solution to set envs.

    So an env: section would be great.

  3. szepeviktor commented on Oct 24, 2018

    @szepeviktor
    ContributorAuthor

    BTW The DotEnv project is for development only, for example Laravel caches its values in a plain PHP file.

  4. schlessera commented on Oct 24, 2018

    @schlessera
    Member

    Trying to discuss through this to find out whether we're actually improving something here...

    So you have your environment variables as real environment variables on your server, not inside of a .env file. That is generally how you should set up a production server, whereas you'd be fine with a .env file on development machines. All fine here if the servers you are referring to are production machines and you access them over SSH.

    However, what you have proposed above to add an env: section to wp-cli.yml would have the same security drawbacks than a regular .env file, only that is then specifically tied to a WP-CLI implementation, instead of the more standard .env file convention.

    The only way to avoid reintroducing the drawback of a .env with such a config change would be to have the env: section in your global user config ~/.wp-cli.yml under aliases. However, that means that you have all sorts of project internals for all of your sites inside of one global config. Are you sure that would improve your situation?

  5. szepeviktor commented on Oct 24, 2018

    @szepeviktor
    ContributorAuthor

    You know it seems much simpler to me.

    1. store secrets in the current ~/website/wp-cli-envs.php file (also a file)
    2. store secrets in ~/website/wp-cli.yml resulting in one less file (also a file)

    I generally discourage developers to use .env for WordPress. Using real environment variables is OK.

    ps. my policy is to have one Linux user with a /home/ directory for each website - usually 1 website per server

    ps2 document root is ~/website/code/ so wp-cli.yml lives above it

  6. schlessera commented on Oct 24, 2018

    @schlessera
    Member

    I generally discourage developers to use .env for WordPress. Using real environment variables is OK.

    In your scenario, I don't see why having environment variables in ~/website/wp-cli.yml would be any better than having them in ~/website/.env, though. The only difference I can see is that the latter is a standard convention.

    I'll leave this issue open here for now, and maybe mention it during office hours, to see whether other folks might have insights to share.

  7. szepeviktor commented on Oct 24, 2018

    @szepeviktor
    ContributorAuthor

    than having them in ~/website/.env, though.

    It could be a misunderstanding. In my case there is no such option!

    https://github.com/vlucas/phpdotenv says:

    phpdotenv is made for development environments, and generally should not be used in production.

    so I do not allow it nor in PHP-FPM nor in CLI.

    It is a wp-cli-envs.php vs. wp-cli.yml decision, not a wp-cli.yml vs. .env one.

  8. drzraf commented on Aug 20, 2024

    @drzraf

    I've a valid use-case for this: environment variables related to wp-cli connection settings, namely ssh/docker.

    Assuming my-test-container is hosted on test-server (available via ssh):

    # .wp-cli/config.yml
    @remote-wp:
      ssh: docker:my-test-container/var/www
      env: {} # hypothetical feature

    Then it makes sense to have DOCKER_HOST set within .wp-cli/config.yml instead of doing:
    DOCKER_HOST=ssh://test-server wp @remote-wp core version

    It's also less error-prone (eg: if the same container name exists locally): the container name and the host serving it are configured in the same file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions