If you create a WordPress website, it is good practice to first create a development site on your own computer then move it to your webhosting when it is finished.
You can’t just upload the website and database, it won’t work because WordPress uses absolute URLs and these will all need changing.
You may also want to move your website to a different domain name, or change it from http to https.
You can use plugins to do this. However, editing the URLs in the database is straightforward and this is the method which we will be looking at in this tutorial.
You will need to upload the files for your WordPress site to your webhosting using FTP or you can use an installer such as Softaculous to install WordPress.
Installing WordPress manually
To create a new database and user, the steps are as follows:
- Open phpMyAdmin from your control panel
- Create a new database
- Click on the ‘privileges’ tab then click ‘add user’
- Change the host to local
- Create a password for the user
- Check ‘Grant all privileges on database “yourdatabasename”.’
You will now need to export the database data from your old website. and import it to the new one.
- Select the database and click export
- Select ‘Custom – display all possible options’
- Select ‘Save output to a file’
- Find ‘Compression’ and select ‘gzipped’
- Scroll to the bottom and click go
- Now you can import the data to your new database
- Select the database and click import
- Click where it says ‘browse’ and select the database file you created
It will take a while to import the data especially on slower web hosts
Create a copy of the wp-config.php file and edit it as follows:
- Find where it says ‘database_name_here’ and change it to your database name
- Find where it says ‘username_here’ and change it to your user name
- Find where it says ‘password_here’ and change it to your password
You can normally leave the host name as localhost, but see instructions from your webhost if the database is on a different server
Find where it says ‘$table_prefix = ‘wp_’;’ and change wp_ to the table prefix you used for the development website. For good security it should be something other than the default wp_.
Now you can use FTP to upload the WordPress files. You need to see instructions from your webhost to find out where this is. You need to upload your edited wp-config file.
Using an installer
If you have used an installer to install WordPress on your webhosting, proceed as follows
- Upload the wp-content directory from your old site
- Import the database data you exported from your old website, follow the instructions above
- Edit the wp-config.php files to the prefix you used for your old website
- Delete the tables with the prefix the installer created
Change the URLs
At this stage, all the files and database you need will be installed. But your website will not be working.
- Go into phpMyAdmin, select your database and select SQL
- You will now be able to run queries on the database in the field which appears
Here are the queries you need. The examples use https and assume you have an SSL certificate installed. Use http if you don’t.
Change the site URL
UPDATE wp_options SET option_value = 'https://example.co.uk' WHERE option_name IN ('siteurl', 'home')
You will need to change ‘wp_’ in ‘wp_options’ to the table prefix you used for your old website and change ‘https://example.co.uk’ to your new website domain name.
Change the URLs in the posts
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://localhost/oldwebsite', 'https://example.co.uk')
You will need to change the website URLs to whatever you used for your development site.
Change the URLs in the post meta data
This will only apply to some websites, for example if you used the Advanced Custom Fields plugin.
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://localhost/oldwebsite', 'https://example.co.uk')
If you have used URLs in your widgets, you will need to log into your WordPress website and change them manually.
Check the home page of your website, it should now be working.
Now check that the other pages are working. If you get an error, log in to your WordPress website and switch the permalinks off and on again.
Changing from http to https
You will only need to do the database queries to change http to https.