Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

359
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda