0

I'm in a somewhat odd development situation where I need to develop a WP site at http://dev.example.com/ and then make it live at https://example.com/.

The summary is:

  1. Develop on http, publish on https
  2. Develop on dev.example.com, publish on example.com

What should be done on the WP side of things? Is it as simple as updating the db replacing all occurences of http://dev.example.com to https://example.com?

What about wp-config.php?

I'm aware that plugins will probably have their own options that need updating. I'm mainly concerned about the core requirements. Media library links comes to mind.

Heck, maybe there's even a plugin that will do this for me? Or maybe development should be started in a specific way / or with a specific plugin?

I'm an experienced developer, but new to the WP-side of things. I'm very comfortable around the linux/db command line. I'm mainly looking for the general outline, but feel free to be as specific as you like. Every bit of info will help me sleep better at night.

5
  • we using de.wordpress.org/plugins/duplicator for such stuff, saves us alot of work and must stuff work
    – StefanBD
    Commented Apr 12, 2023 at 16:25
  • Yes, I agree with @StefanBD, the Duplicator plugin is a pretty robust solution, we use it at our company with basically every website we publish. It takes care of every situation you mentioned in your question in very straightforward steps.
    – YourManDan
    Commented Apr 12, 2023 at 16:31
  • Good stuff, thank you both for the info. I'll leave the question up in hopes that someone happens along that can give me a technical answer of what needs to actually happen. e.g. edit these db entries, update your wp-config.php, update your .htaccess, etc.
    – Jeff
    Commented Apr 12, 2023 at 16:37
  • i think the wp-site url in the wp_config and also the url in settings. After you should update 1 time the perm links in options and it should update the db and the .htaccess.
    – StefanBD
    Commented Apr 12, 2023 at 16:45
  • for the rest i would do a string replace in the mysql dump
    – StefanBD
    Commented Apr 12, 2023 at 16:50

1 Answer 1

1

I'll try to outline the fundamental steps — your mileage might vary, depending on your actual setup. I tend to manage WordPress deployments in an automated manner (e.g. Ansible), so I have a preference for command-line scripts and config files.

  1. Define the home and site url in the wp-config.php file of your production environment (the one on HTTPS):
define( 'WP_HOME', 'https://example.com/' );
define( 'WP_SITEURL', 'https://example.com/' );

These have precedence over the corresponding settings (WordPress Address (URL) and Site Address (URL)) in your SettingsGeneral screen. Having them in wp-config.php also ensures they're instantly and correctly setup at deploy time.

  1. Copy over your database (I do this via the mysql command line utility).
  2. Copy over all files in your wp-content folder (including uploads).
  3. Use WP CLI to search and replace URLs across the whole database:
wp search-replace 'http://example.com' 'https://example.com'

That's basically it for WordPress itself. Finally just make sure your web server is redirecting all traffic from http to https.

2
  • Great answer, exactly what I was looking for. Question about wp cli, how does it know which site you're targeting? Do you have to cd to the site directory first? I checked the docs, but it was unclear.
    – Jeff
    Commented Apr 13, 2023 at 14:10
  • 1
    You can either cd into your site root directory (where wp-config.php is, by default), or run it from everywhere and specify your WordPress path with the --path option. See Global Parameters. Commented Apr 13, 2023 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.