In my earlier posts, I talked about how to back up your WordPress Database, followed by how to copy off the files which make up your WordPress blog using FileZilla. We now come to what is potentially the most technically challenging part of the series. Where to host a cloned WordPress website.
What does “Host a WordPress Website” mean, anyway?
When we talk about hosting, we are talking about where the files which make up your WordPress website or, in fact, any website you visit, are. Depending on what package you chose when you bought your hosting, you can often have what are known as sub-domains as well as your main website domain name. A sub-domain is the bit before your domain name, such as www.stevenspiller.com, forum.stevenspiller.com or blog.stevenspiller.com.
Some shared hosting providers do not allow the use of sub-domains. If you are unable to have a sub-domain, you can usually have a sub-folder. This is the bit after the first forward slash (/) after your domain name such as www.stevenspiller.com/blog/ or www.stevenspiller.com/forum/. There are downsides and upsides to both options, but for the purposes of this tutorial, we are going with a sub-domain.
I am using cPanel, which is one of the most popular web-hosting control panels in use. Yours may look a little different to mine, but the basic operations are the same. If you do not have cPanel, then the process involves same basic principles; you will need to read up on how to carry out the task in your hosting control panel.
1. Create a Sub-domain
Once you are successfully logged in to your cPanel, head down to Domains and click on Sub-domains. When you fill in the sub-domain name and hit tab, it will fill in the Document Root with a default value of /<web-root>/<sub-domain>. So for wp-clone sub-domain it will be /public_html/wp-clone. Click the create button. That’s it! You now have a sub-domain to put a copy of your website to play around with, with will not interfere with your main, live website.
Now, you need to follow a few rules regarding sub-domain names. Only use alpha-numeric characters (a-z, 0-9), underscores (_) or hyphens (-). No spaces, strange characters or other punctuation marks. You can use a full stop (.) but I recommend against.
2. Upload Files
Now we have our sub-domain, we can start uploading the files we downloaded in How to Manually Back-up a WordPress Website. In FileZilla, log into your FTP and open the directory created above. Upload all the files from your local computer to the new directory by highlighting them all on the left side (Ctrl+A or right-click and Select All) then right-click and select Upload from the menu.
3.a. Create a New MySQL Database
Moving on, we will create a new Database to store the information for our cloned website.
- In cPanel, click Home, and then scroll down to Databases
- Click on MySQL® Database Wizard
- Fill in the New Database: box with a random string of letters and numbers. Write this down and click next
- Fill in the Username: box with either the same characters as the previous step or add some other random characters. Write this down
- Click the Password Generator button
- Write down the randomly generated password for later. Tick the I have copied this password in a safe place box and click use Password
- Click the Create User button
- Tick ALL PRIVILEGES and then click Next Step
You now have a new database, ready to take information from the live site. Now we have our new Database, we need to edit a file in our WordPress clone. In FileZilla, right-click on the file called wp-config.php and change the following:
define(‘DB_USER’, ‘<old Database username’);
define(‘DB_USER’, ‘new Database username’);
define(‘DB_PASSWORD’, ‘<old Database password>’);
define(‘DB_PASSWORD’, ‘<new Database password>’);
Save and close the file. FileZilla will detect the file-change and prompt you to upload the edited file.
3.b. Edit the Database Backup File
There is one last change we need to do to make sure your clone site does not interfere with the live site. Open up the Database backup we created in How to Create a WordPress Database Backup. search for your websites’ current address and change to the new address.
- Press Ctrl+H or got to Search, Find and Replace in your text editor
- Search for your websites current address; e.g www.domainname.com
- Replace all occurrences with the sub-domain name; e.g sub.domainname.com
- Save the file and exit
3.c. Unable to Create a New Database
Some of you may not be able to create a new MySQL Database. This is not a problem as we can get around this in this alternate step. If you were unable to create a new MySQL Database in the previous step because your host only allows you one database, we need to edit the database backup file we created in How To Create a WordPress Database Backup. If you do not do this step, you will overwrite your Live database with the backup.
- In your remote WordPress directory, open the file Open the file called wp-config.php
- Look for the line that starts $table_prefix and write down the character between the single quotes (‘)
- Change the characters to something random, no more than 4 characters long and make a note of the new ones. Ensure you keep the underscore as the last character.
- Open the Database backup file; be aware that you may have to wait a while if it is rather large. If it is more than a couple of MB in size, I would suggest using a proper text editor such as Notepad++ instead of Windows Notepad
- Do a Search and replace (Ctrl+H) for the old table prefix and replace with the new one from above
- Save the edited file as a new file and close
You will need to note down the name of the Datahase found
4. Upload and Import the Live Database Backup
Now we are ready to upload the Database so we can have our clone use the information.
- In cPanel, Databases, click on phpMyAdmin
- In the left column, find and click on the name of the database you created above, or your original database
- Click Import in the top menu
- Click Choose File and select the either the database backup file or the edited version from above.
- Click go at the bottom
phpMyAdmin will import the database information into the selected database.
That’s it! You should now be able to browse to your new sub-domain and see your website. Browse around your new clone, checking the URL stays on your sub-domain and does not switch to your live site.
This is the fourth post in a series about Cloning a WordPress Website.