Moving a WordPress site from local to live
As a follow up to my previous post on Setting up a WordPress local development environment, the next step is Moving a WordPress site from local to live. You have your site just as you want it locally, and and would like to see exactly the same on your live server. The first step is to find yourself a WordPress host, I use names.co.uk but there are plenty to choose from here. I wanted to make sure my local site stayed exactly as it was for further development, no messing with its .config files etc so decided to work from a back up, and upload from there. Its taken me a while to develop a process I am comfortable with, and this approach now works for me, so here goes …
Step 1 – Back up your files
Setup a separate folder on your desktop called ‘yoursitename_backup’ and copy the entire contents of your local ‘wordpress’ (or alternatively named) folder to here. In my case the files are in MAMP / htdocs / wordpress.
Step 2 – Back up your database
Go to your local pHpMyAdmin (via MAMP Welcome Screen)
Click on the database name in the left hand column
Click on the Export tab and select ‘all files’ for export
Check ‘Save as File’ and then ‘Go’ to export a .sql file
Put this in your backup folder
Step 3 – Setup a Database on your host
Login to you hosts control panel and navigate to your MySQL Databases. ( In my case – CP > Domain Names > yoursite.co.uk > MySQLDatabases)
Add a database and enter your details for Name, Password and Username (you will need these details later to edit your config.php so take a note of them including the name of your MySQL Server.)
Select your new database and login via phpMyAdmin, click on your database name in the left column.
Click on the import tab then browse to locate your exported database in your backup folder, select and import.
Once imported, you will see the wordpress tables appear in the left column, and details of those tables in the main area.
Step 4 – Edit your host database
Congratulations, you now have all your WordPress content in your database, content for post pages etc. We now need to edit two values in your database tables as they currently reference your local database. To do this you.
Click on wp-options in the left column, then click on the browse tab to see details of this database table.
Find ‘siteurl‘ in the ‘option_name’ column and change your ‘option_value’ from localhost:8888 to http://yoursite.co.uk
Find ‘home’ in the ‘option_name’ column, and change the ‘option_value’ from localhost:8888 to http://yoursite.co.uk
Step 5 – Point WordPress to the new database
Find your config.php file within your WordPress files in your backup folder and open in a text editor. This will currently be pointing to you local sites database. Edit the details to correspond with your new database login details. These are the details that you have recorded above, or you can check with you host if you are unsure.
Step 6 – Copy your WordPress site to live
FTP all your WordPress files from your backup folder to the root folder of your live site via your preferred ftp method – this takes a while.
Step 7 – Search and Replace URLs
Finally – there will be references in your database for image paths etc that will need to be changed for everything to display correctly. I have used this script to Search and replace all urls in database. Take care with it and make sure you delete if afterwards, there are step by step instructions on the website, but basically you rename it, add it to your root folder, access it via http://yoursite.co.uk/yourscriptname.php and follow the prompts.
Step 8 – Check your live site
Everything should now be up and running, check your site and access via admin (http://www.yoursite.co.uk/admin) – login with the same login details as your local site.
WordPress also has details here of how to move sites http://codex.wordpress.org/Moving_WordPress. There may be other ways of doing this and in the end its about finding a process that you are comfortable with. I hope this helps someone that is going through the same process and any suggestions for other ways, extra information, things I may have missed etc are very very welcome.