This is a step by step guide on how to transfer local WordPress sites to a live server. The server I am using in this article has a cPanel backend. This guide follows on from my article on how to install WordPress locally using MAMP.
1 – A local WordPress installation (please see my previous guide on setting this up).
2 – A remote hosting package including domain name.
3 – An FTP program such as FileZilla.
Go to phpMyAdmin via your browser using the following path:
http://localhost/phpmyadmin/
Click the Export tab, as shown in the image below:
Leave the options as default (Quick export) and click Go then save the exported file.
The next step is to upload all of your WordPress files to the remote sever. There are a couple of options here, you can upload all of the individual files to the remote installation folder via FTP, or (using cPanel) you can zip all of the files together as one archive, upload them and extract them directly on the server (this method is much faster).
Just be certain that you are uploading everything to the correct directory – e.g. if you are are aiming for the root of your domain, the path will be:
/public_html/
Options to transfer local WordPress installation:
Option 1 / FTP – Upload directory contents as individual files and folders to your installation directory on your live server:
Option 2 / cPanel – Compress files and folders locally as a single zip file, then upload to installation directory on live server, right click and extract the zip directly on the live server:
Whilst everything is uploading, you can now import your database into the live version of the site.
First we need to create a new database that we will use later to receive the imported data. As mentioned earlier, I am using cPanel for this guide.
Open the cPanel dashboard and head to MySQL Databases as follows:
Then go to Create New Database, enter a short descriptive name and hit Create Database.
We will now add a new user to the database.
Go to Add New User, fill out the username and password, then hit Create User.
Then go to Add User to Database, and in the User drop-down menu, highlight the user you just created, then select the Database drop-down and highlight the name of the database you just created. Hit the Add button.
Set privileges for new user as follows:
Now we can import the database. In cPanel, go to phpMyAdmin:
Click on the database you created earlier (step 4).
At this point you will see that the database has no tables.
Select the Import tab, then hit Choose File and upload the database file you exported earlier (in step 2) from your local WordPress installation.
Hit Go to import the file.
To allow the database to connect to the WordPress site that we uploaded earlier, we must update the site url. Currently it will be pointing to localhost, and we must change this to point to the domain name on the live server.
Whilst still in phpMyAdmin, locate the wp_options table we imported in the previous step. Select it.
Then, hit the Browse tab, and you will be presented with a list of fields in the right hand pane.
The ‘siteurl’ option_name should be edited first (click Edit as indicated by the top arrow in the right hand pane of the image below):
In the edit window (where the arrow is pointing upward in the image below), change the current url from http://localhost to your hosted domain name e.g. http://yourdomain.com
Hit Go to save it. Repeat this step with the option_name ‘home’.
If you now access the site in your browser you will see the following message:
Error Establishing Database Connection
We can fix this by doing the following:
Go to the root of your WordPress installation on the live server, and download the file wp-config.php. Add the database name, user and password (you created these in step 4) then save the file and upload, overwriting the previous version.
When you access your site now, it should be working.
In order to make sure that the site URL is updated everywhere else, and that all post links will work as they should, we must do the following.
In WordPress dashboard, go to Settings / General, scroll right down and hit Save Changes.
Then, go to Settings / Permalinks and hit Save Changes there also.
Congratulations, you just migrated your local WordPress site to your live server.
The final step is to check that there are no broken links on the site.
You can update paths to fix such errors using an SQL query. Before performing this step, please make sure you are confident about what paths you want to search for and replace here. Generally you will be replacing localhost with your domain path, but you should double check everything before running a query.
Go to phpMyAdmin, click on your database and then click on the SQL tab.
Input the following query (update it with your own site details first).
UPDATE wp_posts SET post_content = REPLACE(post_content, ‘localhost/’, ‘www.yourdomain.com/’)