I have a wordpress which works fine in localhost. Now we need to deploy it on our testing environment using docker. Deploy php files with docker was fine. I configured worpdress to use environment variables instead hardcoded values in wp-config.php.
docker run -d --name wordpress -it --rm -p 80:80 \
-e DB_HOST=10.10.10.10:3306 \
-e DB_USER=root \
-e DB_PASSWORD=secret \
-e DB_NAME=wordpress \
-e AUTH_KEY=$RANDOM_KEY \
-e SECURE_AUTH_KEY=$RANDOM_KEY \
-e NONCE_KEY=$RANDOM_KEY \
-e LOGGED_IN_KEY=$RANDOM_KEY \
-e AUTH_SALT=$RANDOM_KEY \
-e SECURE_AUTH_SALT=$RANDOM_KEY \
-e LOGGED_IN_SALT=$RANDOM_KEY \
-e NONCE_SALT=$RANDOM_KEY \
-e WP_DEBUG=true \
-e DISABLE_WP_CRON=true \
-e TZ=America/Lima wordpress:5.7.2
The problem is in the database deployment. I exported a dump from my localhost and imported to my new testing database. I saw that in the database dump, all the urls are hardcoded with localhost:
table wp_options
'siteurl','http://localhost'
table wp_posts
'you should go to <a href=\"http://localhost/wp-admin/...''
table wp_users
1,'admin','****','admin','admin@mail.com','http://localhost'
When I try to access to my testing domain, assets are being downloaded from localhost, ignoring my domain. I understand that this behavior is due to the hardcoded "localhost" in the exported db from developer machine.
Research
WP on localhost to wordpress's domain
- I which show another way to export the database from localhost.
-
- I'm not a wordpress/php programmer, so I don't know if these variables can be dangerous.
Questions
- What is the best strategy to move from localhost to another environment in wordpress for a devops pipeline in which all is handled with variables and human intervention is not required?
- Would a simple string replacement (localhost > wordpress.testing.com) in the mysql dump work?
