Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getenv_docker in wp-config.php does not read environment variables from docker-compose #664

Closed
winkee01 opened this issue Nov 26, 2021 · 1 comment

Comments

@winkee01
Copy link

The previous issue was not respected, so I open a new issue here.
The symptom is that getenv_docker function does not read any environment from docker-compose, thus causing the failure to connect to the database.

The symptom is repeatable, for simplicity, I uploaded my docker-compose.yml and related source file into a repo: https://github.com/winkee01/docker-nginx-php-fpm.
After you clone it to your local directory.

Follow the below steps:

mkdir run
docker-compose up
docker exec -it nginx-php bash
> usermod -u 82 www-data && groupmod -g 82 www-data && nginx -s reload
> exit
echo "your_ip testwp.ok" >> /etc/hosts

import `nginx/ssl/testwp.crt `to your browser (or keychain on macOS) so that you can use https

open URL testwp.ok in your browser.

a bit of explanation
We must change the user & group in nginx container because it has to be the same with the user, and its uid & gid also has to be the same. And that's why we need to login to nginx-php container to make the changes.

In browser, you will see this symptom:

JPEG 2021-11-25 at 14 09 39@2x

The reason is
getenv_docker function in wp-config.php failed to read environment variables passed in docker-compose.yml.

You can verify this by entering php-fpm container,

docker exec -it php7.4fpm bash
env | grep WORDPRESS

the variables are correctly shown, but wp-config.php failed to read them.

If you change the variables' value in wp-config.php to the correct ones, you will load the site successfully.

@tianon
Copy link
Member

tianon commented Nov 29, 2021

As I noted in #576 (comment), if you're going to overwrite the entire php-fpm configuration, you'll need to make sure you configure it in a compatible way (namely, setting clear_env = no).

In the future, these sorts of questions/requests would be more appropriately posted to a dedicated support forum, such as the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

@tianon tianon closed this as completed Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants