-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix Error: Could not process the 'wp-config.php' transformation #29800
Fix Error: Could not process the 'wp-config.php' transformation #29800
Conversation
packages/env/lib/commands/start.js
Outdated
await dockerCompose.exec( 'wordpress', 'chown www-data:www-data wp-config.php', { | ||
config: dockerComposeConfigPath, | ||
log: debug, | ||
} ) | ||
|
||
await dockerCompose.exec( 'wordpress', 'chmod 777 wp-config.php', { | ||
config: dockerComposeConfigPath, | ||
log: debug, | ||
} ) | ||
|
||
await dockerCompose.exec( 'tests-wordpress', 'chown www-data:www-data wp-config.php', { | ||
config: dockerComposeConfigPath, | ||
log: debug, | ||
} ) | ||
|
||
await dockerCompose.exec( 'tests-wordpress', 'chmod 777 wp-config.php', { | ||
config: dockerComposeConfigPath, | ||
log: debug, | ||
} ) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that manually changing permissions for wp-config.php
is the right fix, see discussion at #29770 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have a good point that configuration should be set idiomatically via docker-compose configuration.
However, I think it would still make sense to fix wp-config.php
permissions, because currently wp-config.php
is owned by root and so any commands that need to use the config for any reason would fail.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've had to update permissions for some of these files to get them to work in wp-env before, so I'm not against it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use WORDPRESS_CONFIG_EXTRA
because the wordpress
image will only use that variable if wp-config.php
doesn't already exist which isn't very flexible for developers. For example: you wouldn't be able to update WP_DEBUG
in .wp-env.json
, restart wp-env
, and see WordPress running in debug mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use
WORDPRESS_CONFIG_EXTRA
because thewordpress
image will only use that variable ifwp-config.php
doesn't already exist
I'm not totally sure, but I think that's no longer true per docker-library/wordpress#557, which has wp-config.php
read those values dynamically from the docker env (using a getenv()
helper); see e.g.
WORDPRESS_DEBUG
: https://github.com/docker-library/wordpress/pull/557/files#diff-7f28a0f62019f2d8b061638e8c3aea207404c1499f1c9241db3216fadd8f4530R99 orWORDPRESS_CONFIG_EXTRA
: https://github.com/docker-library/wordpress/pull/557/files#diff-24f50e34cd95d8171662daf812269748e400594db64a7ee63ffd1fb3db5d9965R108-R110
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I have not run wp-env in several weeks, so my docker image probably wasn't updated at first.
When running npx wp-env start
, I first got this issue:
After running npx wp-env start --update
, I get the following error:
~/source/gutenberg(fix/wp-env-docker-compose) » npx wp-env start --update noahtallen@Noah-MBP16
✖ Error while running docker-compose command.
Creating a86349ed83984e487ba92af16fae23af_cli_run ... done
mysqlcheck: Got error: 1045: Access denied for user 'root'@'172.18.0.6' (using password: YES) when trying to connect
You get that error because the database So if you delete volumes with I don't know if there's anything we can do about this. |
Is this just a one-time problem? |
Because of changes by @youknowriad from #29770 (which this PR extends), the database is always going to be created properly in the future. So it should be a one time problem. |
Username: |
Ah, FML, not sure why that slipped my mind! Thanks :) Looking into the PHPunit stuff now |
Hm. |
The phpunit container is still missing the WORDPRESS_DB_* environment variables. Tests were failing for me because of this with "wpdie called" as the only output. |
Interesting, I wonder why they passed locally for me in that case. It totally makes sense though. @ribaricplusplus it might make sense to pull out the wordpress constants into their own object so that we don't have to repeat them everywhere. e.g.: const databaseEnvironment = {
WORDPRESS_DB_NAME: 'tests-wordpress',
WORDPRESS_DB_USER: 'root',
WORDPRESS_DB_PASSWORD: 'password',
WORDPRESS_DB_HOST: 'tests-mysql',
};
// later on, in the compose config:
environment: {
...databaseEnvironment,
} |
}, | ||
volumes: [ 'mysql:/var/lib/mysql' ], | ||
}, | ||
'tests-mysql': { | ||
image: 'mariadb', | ||
ports: [ '3306' ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This port is already being used by the mysql
container above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think those ports just denote which ports are exposed within a container. Ports are isolated within individual containers, so if I'm not mistaken there should be no conflict.
EDIT: According to compose specification this short notation means that the port 3306
inside the container is going to be assigned an ephemeral port on the host machine. Still, that means there should be no trouble.
}, | ||
volumes: [ 'mysql:/var/lib/mysql' ], | ||
}, | ||
'tests-mysql': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big fan of adding an extra MySQL container. It will mean there's a lot of extra memory usage and startup time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we keep to a single container and create two databases ourselves using wp db create
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could that be a follow-up task? It seems higher effort than the current approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep absolutely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using one database, and different table prefixes for dev and tests, respectively? The wordpress
docker image supports a WORDPRESS_TABLE_PREFIX
env variable for that purpose.
@noahtallen Did that with the last commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, let's merge this now to get everything working. For follow up:
- Figure out a better way to consume Docker (perhaps our own docker image, or one of the ones maintained by wordpress) so that we don't run into this issue again.
- Move away from a separate tests-mysql, perhaps creating the test DB manually in the installer script.
- Resolve anything else that might not be working (unsure if anything else is broken.)
- Push this change to npm ASAP.
I'm stepping away soon, so passing the torch on to the next person :)
- Use separate tests database service - Configure database credentials in every service - Set wp-config.php to be writable Co-authored-by: Riad Benguella <[email protected]> Co-authored-by: Noah Allen <[email protected]>
I cherry-picked commit with this PR to |
- Use separate tests database service - Configure database credentials in every service - Set wp-config.php to be writable Co-authored-by: Riad Benguella <[email protected]> Co-authored-by: Noah Allen <[email protected]>
- Use separate tests database service - Configure database credentials in every service - Set wp-config.php to be writable Co-authored-by: Riad Benguella <[email protected]> Co-authored-by: Noah Allen <[email protected]>
Description
This is an addition to #29770
#29770 Seems to fix the access denied error, but then a new error arises described in this comment #29770 (comment)
This PR fixes that error and it should close issue #29752
How has this been tested?
Running
wp-env start
from an empty directory