Updating WordPress URLs in a database and testing

One of the last things on our 'Go Live' checklist is to repoint the domain to the server where the new site is. There are a few things you need to do before this can happen.

When making a WordPress site live you need to update the development URLs to the current URL. The easiest way to do this is by using a database script to run a find and replace on all the tables that could store the site address. The below can be used by swapping ‘oldsite’ and ‘newsite’ with the dev and live URLs respectively. If you have changed the default WordPress table prefix from ‘wp’ you will need to update that also. Whilst it is not always necessary, we recommend taking a backup of your database if you’re not that confident working with MySQL.

Screen Shot 2016-02-29 at 14.11.03

UPDATE wp_options SET option_value = replace(option_value, 'https://oldsite', 'https://newsite') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'https://oldsite', 'https://newsite');

UPDATE wp_posts SET post_content = replace(post_content, 'https://oldsite', 'https://newsite');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://oldsite', 'https://newsite');

If USING A SCRIPT seems too technical, there are lots of plugins out there that can help! OUR FAVOURITE IS GO LIVE UPDATE URLS.

Now that your database is using the new site URL you will not be able to view it from your dev link. Before we repoint the domain we need to ensure that our site is still working as expected with the new url. To do this we need to add the site URL to our host’s and redirect it to the development server’s IP. Here’s how…

For Mac OS

  1. Open your terminal.
  2. Make sure you’re in the home directory, cd ~.
  3. Open the hosts file for edit by running:
    sudo nano /private/etc/hosts
  4. It will then ask you for your password.

  5. The file should have the below contents:

    ##
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting.  Do not change this entry.
    ##
    127.0.0.1       localhost
    255.255.255.255 broadcasthost
    ::1             localhost
  6. Making sure not to edit anything that is already in this file, add a new line with your server’s IP and the new url.

    87.87.87.87 newurl www.newurl
  7. Save the file (Ctrl-O)

For Microsoft

  1. Open Run Line and enter the below command. This will open the host file in notepad.
    notepad c:\windows\system32\drivers\etc\hosts
  2. Now follow points 6 onwards from the ‘For Mac’ instructions.

You can now access the site from your browser and check that it is working as expected. Remember to remove the added line from your host files so that you can see when the DNS has been updated and propagated.

Check back soon for more TWK developer tips!

Get in Touch
Latest Tweet

We've really enjoyed this fun and exciting project - a great opportunity to do something different and surprising. Check it out for yourself: https://t.co/99Dcv5u9kS #launch #webdesign #webdev #webdevelopment https://t.co/WVYcxUefTI

July 23, 2020