Short Code: 78DDJ4KA8RS4

This article will guide you on how to clone your WordPress website and run it on your local machine. Why should you clone a WordPress website ? Read through the rest of the article to get the answer yourself. Though there are lot of plugins available to do this job, doing it manually(i still use a plugin to backup) will help you to understand what’s happening under the hood.

Wait!!!  Before we proceed any further into the article i would like to point out that you require the below things, you can still read through the article but you will benefit more if you have all these three with you:

  1. Apache XAMPP installed on your local machine.
  2. A  WordPress website up and running live.
  3. Simple Backup Plugin installed on your WordPress website.

Why would someone clone their WordPress website locally?

WordPress Logo

So coming back to our question “Why do i need a clone?” There are lot of valid reasons to have a local copy(guess that defines cloning) of a WordPress website and below are some reasons for why i prefer to have a local copy:

  • I usually Test Drive the new WordPress plugins in my local copy. It gives me lot of control and since its running on my local machine it costs me nothing and the other benefit is, I don’t have to worry about the “what if I make a mistake?” syndrome.
  • Since WordPress doesn’t have a maintenance mode feature inbuilt, I gave a trail run on my local machine by playing around the theme a little before Artic Post went live. This way your readers won’t be annoyed to see your article’s font or look and feel getting changed every now and then.
  • I would like to tweak some of the core files in the WordPress directory to make things work or see how WordPress behaves, however this is not a best practice since changing core files may actually screw up your website so it’s strictly not recommended on live server.
  • The WordPress clone i create is my test playground server.

I don’t want to keep you waiting anymore, we shall see how to take a backup of a WordPress website and restore it on your local machine.

Backup Your WordPress Website Today

The first step involved in creating your clone is taking backup. You would have spent a lot of effort on your website and it would be really awful, if you lose all those content that you have created. It is always advisable to take regular backups of your website to avoid loss of data. Even if you don’t want to have a clone taking regular backups of your WordPress website is mandatory. There is no out-of-the-box feature provided by WordPress to back up your complete website but worry not, you can leverage WordPress plugins to accomplish this.

  5 Simple Steps to Back up Your WordPress Website

Though there are lots of backup plugins available to backup WordPress i have chosen Simple Backup Plugin for two reasons, first it’s simple and second it’s very simple.

Follow the below quick steps to take the backup of your WordPress website:

1) Login as administrator into your WordPress website and Install Simple Backup Plugin from your Add New Plugin page.

2) Once the plugin is installed navigate to Simple Backup Plugin Settings, you should be able to locate it under the WordPress settings menu.

3) You would have to configure some basic settings to have your first backup, refer the below screenshot for your reference.

Simple Backup Settings

4) Once you have configured the settings click on Create WordPress Backup button and your backup will be generated and available in the Backup Manager Tab.

5) Two zip files will be available for you to download in the Backup Manager Tab as shown in the below screenshot, one is your database backup and other one is your WordPress backup.

Backup Manager

Great Job your WordPress backup is ready, now lets get into some real action

Restore Your WordPress Backup on Your Local Machine

I will be restoring the backup files to the XAMPP that I have already installed on my local machine and I don’t want to tell you how to configure and run XAMPP since there are already numerous articles available which can help you to easily set it up within minutes. I am running XAMPP on port 81, you may be on port 80 which is default one so change accordingly wherever applicable. So let’s get started with the restore process, follow the below steps to restore your WordPress website backup on local machine:

1) Download the two backup files that were generated earlier from the Backup Manager Tab.

2) Launch phpMyAdmin from XAMPP and click on the database tab as shown below and provide the same database name that your live server uses.

PhpMyAdmin Create Database

3) Now select the newly created database which would be listed on the left pane and click on the Import Tab from the right pane.

4) Now choose the database file that you have already downloaded in Step 1 and import it using the browse button as highlighted below. Your database backup file will have db_ as prefix in its file name.

Import Database

Note that the maximum size for uploading the file is set to 2 MB by default and you should change it first. If you have already done this you skip this “How to change the import size limit?” step and go to step 5

How to change the import size limit?

a) Locate the php.ini file from your XAMPP installation folder, mine is located at C:\xampp\php\php.ini

b) Edit the file using notepad or any editor of your choice and locate upload_max_filesize=2M and change it as upload_max_filesize=12M. Refer the below screenshot for reference. Save the file and restart your XAMPP Server.

PHP INI File

5) Once you have successfully imported the database file the next step is to import the WordPress backup. Create a folder named restorewp inside htdocs under your XAMPP folder.

6) There is one another thing that we need to do on the database side, we have to change the siteurl value in the wp-options table of your newly created database to point to your local host URL. Refer the below screenshot.

Options Site URL

You may face issues in editing the value in the table and get the below error message

“SELECT command denied to user ‘”@’localhost’ for table ‘pma_table_uiprefs'”.

To resolve this locate the config.inc.php under C:\xampp\phpMyAdmin\ Edit the file and comment the below line and you should be able to edit and change the value in the wp-options table without any issues.

$cfg[‘Servers’][$i][‘pmadb’] = ‘phpmyadmin’;

7) Now extract the other backup zip file which has your WordPress contents, copy all the files and folders and move it under the newly created folder restorewp.

8) Now when you try access the website you should get something as shown below, which is a good sign.

Error establishing database connection

9) Now to fix the above error locate the wp-config.php file under C:\xampp\htdocs\restorewp and edit it. Change or set the correct values for DB_NAME, DB_USER, DB_PASSWORD and DB_HOST.

10) Open the .htaccess file and replace the contents with the below content:

# BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase / restorewp /

RewriteRule ^index\.php$ – [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . / restorewp /index.php [L]

</IfModule>

 

# END WordPress

########

php_value upload_max_filesize 50M

php_value post_max_size 50M

php_value max_execution_time 500

php_value max_input_time 500

#########

11) Now you should be able to login into the admin panel without any issues.

12) When you try to visit your website using Visit Site option from your WordPress admin area you may notice that it will take you directly to the live server. To point it to your local folder, click on Settings in your Dashboard and change the Site Address (URL) to http://localhost:81/restorewp

Bravo, you have cloned your WordPress website on your local machine. Didn’t work for you? Did i miss something ? Do let me know how it went.