Back to blog

How to change WordPress URL safely in production (WP-CLI, SQL, and wp-config fallback)

2/10/2025 · 1 min · WordPress

Share

Changing WordPress URL in production can break login, media, plugin callbacks, and caching if done without a controlled process. This is the workflow I use in real migrations.

Core options

Pre-change checklist

cp wp-config.php wp-config.php.bak.$(date +%F-%H%M)
mysqldump -u DB_USER -p DB_NAME > /root/wp-url-change-$(date +%F-%H%M).sql

Preferred method: WP-CLI

wp option get siteurl
wp option get home

wp option update siteurl 'https://newdomain.com'
wp option update home 'https://newdomain.com'

wp search-replace 'https://olddomain.com' 'https://newdomain.com' --all-tables --dry-run
wp search-replace 'https://olddomain.com' 'https://newdomain.com' --all-tables

SQL method (when WP-CLI is unavailable)

SELECT option_name, option_value
FROM wp_options
WHERE option_name IN ('siteurl','home');

UPDATE wp_options SET option_value='https://newdomain.com' WHERE option_name='siteurl';
UPDATE wp_options SET option_value='https://newdomain.com' WHERE option_name='home';

Use caution with serialized data. Prefer WP-CLI when possible.

Emergency fallback in wp-config.php

define('WP_HOME', 'https://newdomain.com');
define('WP_SITEURL', 'https://newdomain.com');

Post-change validation

  1. frontend;
  2. admin login;
  3. media upload;
  4. permalink navigation;
  5. cache purge;
  6. browser console mixed-content check.

Rollback

Restore SQL dump and wp-config.php backup, then purge cache again.

Final takeaway

A production URL change is a controlled migration task, not a single command. Structured validation and rollback make the operation predictable.

CC BY-NC

This post is licensed under CC BY-NC.

Comments

Join the discussion below.