Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

363
Views
What is the best strategy to switch from localhost to another environment in wordpress?

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.

errors

Research

  • WP on localhost to wordpress's domain

    • I which show another way to export the database from localhost.
  • WP_SITEURL and WP_HOME

    • 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?
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The wordpress domain is controlled by setting 2 database options:

  • site_url
  • home

If you don't want to change it in database you can do it in wp-config.php

define('WP_SITEURL', $_ENV["USER"]);
define('WP_HOME', $_ENV["HOME"]);

You can make it read from an environment variable and then set that inside the container.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!