Transferring a WordPress site from localhost to a live server

21 September, 2013 by Tom Elliott

As WordPress developers, we’re quite fortunate in that WordPress is one of the easiest Content Management Systems to setup and install. Having said that, a number of things can and do go wrong when moving a WordPress site from a localhost development environment to the live URL.

Hopefully this guide will help make the process from moving from local to live as smooth as possible.

I usually develop on my local machine, using a WAMP stack setup to a http://localhost/sitename folder and have made many WordPress websites live from localhost.

The process of transferring from localhost to live using the steps below can probably be achieved in under 10 minutes (depending on connection speed ;)). I’ve tried to focus on the most efficient way to transfer a WordPress site, whilst minimising website downtime.

If all goes well, the final stage of making a WordPress site live should happen within a second or two, virtually instantaneous to anyone that might be viewing the site at the time.

The steps below will also help if moving WordPress from one website domain to another. If you’re concerned about SEO when moving WordPress to a new domain, checkout my post on moving a WordPress website without harming SEO.

Part 1. Move WordPress to a development link on the server

We probably don’t want to move a WordPress site straight to the live URL (unless the site is brand new and has no visitors). This is so that we can get everything setup and tested on the server before we make the site live.

You wouldn’t want to be fixing any database connection errors or redirect issues for example on a live site. There may also be slightly different versions of PHP, mail server settings or other components different to what your localhost uses which we won’t want to troubleshoot either.

I usually setup a ‘dev’ folder on the live server e,g, http://www.mysite.com/dev

Step 1: FTP upload the site

Upload the entire WordPress folder for the local website including all folders for wp-content, wp-admin etc to the dev folder on the live site. While these files are uploading, you can proceed with the below steps. My FTP program of choice is FileZilla

Step 2: Export the WordPress database as SQL

Export the local MySQL database in .sql format. You’re probably using PHPMyAdmin, so once logged in, select the WordPress database, click the ‘Export’ tab and make sure SQL and ‘quick’ method is selected.

Step 3: Setup new WordPress database

Setup a new MySQL database on the live server and import the .sql file. If you can, keep the existing database name, username and password the same to make the next step easier.

Step 4: Update the WordPress config file

If the remote database, user and host (e.g. ‘localhost’) have the same settings as the local database, you can skip this step.

Otherwise make sure the WordPress config file (wp-config.php in the root), has the same database name, username and password as used in Step 3. Most server environments use ‘localhost’ as the DB_HOST but you can find out what this should be from your website hosts if this is different.

If you still want a local testing environment and your local database details are different to the remote, simply create a copy of this file and rename to wp-config.php in the online folder.

Step 5: Change the .htaccess file

If your localhost website URL looks like http://localhost/sitename/ for example then your .htaccess file (located in the root of your WordPress install) will probably look like:

# BEGIN WordPress
RewriteEngine On
RewriteBase /sitename/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sitename/index.php [L]
# END WordPress

Simply change ‘sitename’ with the name of the folder you’re uploading the site to, e.g. ‘dev’, taking care to keep the trailing slash.

Upload both wp-config.php from Step 3 along with this .htaccess file.

Step 6: Run a find and replace script

This find and replace script will basically search the entire WordPress database and replace any instances of the localhost URL with the online URL. It will change the WordPress and Site Address URL from the master WordPress settings along with any other absolute paths to files, images or other links elsewhere.

Follow the steps as explained on the website. When you get to the ‘What to replace?’ step, enter the localhost path in the ‘search for’ field e.g. http://localhost/sitename and the online URL e.g. http://www.mywebsite.com/dev in the ‘Replace with’ field e.g. Note, the absence of the trailing slash on the end of the URLs.

Step 7: Replace other absolute paths

Hopefully this step won’t be needed but if you’ve created a custom WordPress theme and used absolute paths instead of functions like site_url(); then you will need to update any absolute paths containing the ‘localhost’ URL.

That’s it! If you’ve followed the above steps, there’s a good chance that no other fixes are needed but make sure the website’s key pages and functionality works before making the website live.

Part 2. Make the WordPress site live.

Now that we have WordPress fully working on a dev link, these final steps to make the site live are straightforward.

Step 1: Update the .htaccess file.

All we need to do here is remove the ‘dev’ folder name from the .htaccess file so that it looks like the following:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Step 2: Run a final search and replace

Run the same script again to remove ‘dev’ from the URLs. Essentially we’re replacing http://www.mywebsite.com/dev with http://www.mywebsite.com

Step 3: Move the files to root

Finally, we need to do move the entire ‘dev’ folder into the root which can be done through FTP. As the files are already uploaded from localhost to the server, a simple move command should take a couple of seconds for the files to transfer into the live root folder (which is often named ‘httpdocs’ or ‘public_html’ on many servers).

That’s it! Test the live site and make sure everything works



11 Comments

  • Revanth says:

    I guess widgets wont move with this method.

  • ujita tharani says:

    hello… i followed the steps as you suggested in your blog but still on the server a blank page is coming instead of the home/index page… so will you please help me out with any of the solutions… and one more thing that in my .htaccess file
    # BEGIN WordPress

    # END WordPress
    only this code is present….
    Thank you in advance……

    • Hi Ujita,
      There’s a couple of things you can try in this case. In WordPress admin, under settings->Permalinks – try clicking ‘save changes’ even though you won’t have made any changes. I’ve found this has fixed a blank screen issue before. You might also want to check the .htaccess corresponds to the code above.

      Tom

  • Eben says:

    Great writeup
    Can i move my local site to wordpress.com??

  • Monasoleil says:

    Great article, provided lots of help thanks :)

    • luke says:

      Should probably mention migrate DB plugin for WordPress. Free and it sorts the widget issue and bullet-proofs the find and replace so you wont break things. Used in combine with a compressed FTP and extract (using cpanel etc on the remote side) it makes thing s very very easy.

      Another tip I think is to use ngrok service to preview your WordPress site to clients securely from a local server. Works on Mac very well .

  • Andrej says:

    Sometimes when we are migrating page we can get blank home page.

    I found the problem with the home page not displaying from the base URL. It was because there was a default.html file in the root directory. The old hosting server must had set the order to look for start files to PHP extension as the first default so it ignored the default.html file in the root directory and loaded index.php.

    The new hosting server must have the default extension it looks for as an .HTM or .HTML file and was loading the blank default.html file first. Once I deleted the blank default.html file the hosting server started loading the index.php file and displayed the WordPress home page.

    BR
    Andrej

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    css.php