Make clone from my site on same droplet, for testing purposes, with separate database and files, is it possible and how please?

October 25, 2016 3.5k views
WordPress Development Ubuntu 16.04

Hi, as the title says i want to make clone from my wordpress website on the same droplet, but in different directory and database so i can test plugins and other coding stuff. Can you help me please? Thanks

3 Answers
xMudrii October 26, 2016
Accepted Answer

Yes, that would be possible.

Let's assume following setup:
You have WP in /var/www/html
WP database is called wordpress
User for that database is wordpressuser identified by password.

First you need to copy html directory somewhere else. Let's create folder clone under www and copy html there.

  • sudo mkdir -p /var/www/clone
  • sudo cp -r /var/www/html /var/www/clone/

Enter clone and verify you have html with files there.

Make sure permissions are right, i.e.:

  • sudo chown -R $USER:$USER /var/www/clone/html

Verify WP permissions too.

If everything is there, we need to setup Apache to use it.
I would setup a subdomain for it.

We will make subdomain test for it.
Make CNAME record in DNS settings test @.

Now, we need Apache Virtual Host.
This tutorial will help you. Basically, as you already have directory setup, just create second VHost and enable it.

You need to "clone" database.
First create new database and give privileges to it.
Login to MySQL:

  • mysql -u root -p

Enter password when asked and press ENTER.

Create database:

  • CREATE DATABASE wordpressclone DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

And create new user or give privileges to existing one:

  • GRANT ALL ON wordpressclone.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

Update privileges:

  • FLUSH PRIVILEGES;

Exit MySQL prompt:

  • EXIT;

Make a backup of current database:

  • mysqldump -u root -p wordpress > ~/wordpress.sql

This will create database dump in your home folder.
Open it with any text editor:

  • nano ~/wordpress.sql

And on top of it add:

  • USE wordpressclone;

Save it and exit editor.
Run that file using:

  • mysql -u root -p < ~/wordpress.sql

For last step we need to update WordPress clone config.
Open wp-config.php for clone:

  • nano /var/www/clone/html/wp-config.php

Make sure you set database name to wordpressclone and verify user used for it.
Save it and exit.
Go to http://test.example.com/wp-login.php. Login, go to Settings -> General, update URLs, save and you are good to go.

Good luck, I hope this will work for you, if you have any questions or problems, ask, we will try to help you :)

by Brennen Bearnes
The Apache web server is the most popular way to serve web content on the internet. Apache has the ability to serve multiple domains from a single server by using a mechanism called "virtual hosts". If a virtual host is configured correctly for each domain, the web server can correctly route traffic to the appropriate files based on the domain name requested. In this guide, we'll demonstrate how to configure Apache virtual hosts on an Ubuntu 16.04 server.
  • I am really struggling with this. I have followed these instructions and the tutorial for setting up an apache virtual host, and got an index.html to work fine. So I deleted that file and copied in my wp site files and created the sql database as directed. I'm getting a Error establishing a database connection error. So I poked around online for the error, and found a tutorial about repairing wp databases (https://www.wpkube.com/how-to-fix-error-establishing-database-connection-in-wordpress/) but hit a dead end there too. Can't even run the repair, since still getting EEDC. Any idea what might be going wrong? I am a TOTAL n00b in the back end, so I'm sure I'm just missing something glaringly obvious.

    • I'm getting a Error establishing a database connection error.

      Have you populated your wp-config.php file to include credentials needed to access the MySQL database?

      I recommend you to check the How To Install WordPress with LAMP on Ubuntu 16.04 tutorial. It contains instructions for setting up the WordPress, including installing it, setting up the database and setting up the appropriate permissions.

      If you have any problems, let me know in the comments below, or start a new question.

      by Justin Ellingwood
      WordPress is the most popular CMS (content management system) on the internet. It allows you to easily set up flexible blogs and websites on top of a MySQL backend with PHP processing. WordPress has seen incredible adoption and is a great choice for getting a website up and...

Omg!!! Thanks man, you saved me a lot of headaches, for days i was trying to make this work. At first i tried www.example.com/testsite but i was having so much trouble with importing the database, tried duplicator but it was not working, and on my local PC it worked but that is another story :) . I was sceptical for using the USE wordpressclone; because i didn't know what will happen, but i know that i learned so much from your help!!!

I know that your guide will ease so much headaches for other people too :)))
Thanks again and have a nice day!!!!

Just one question,
how the variables for the PATH in the database changed ? I mean the path to the images and stuff, i really don't get that. Please post some link so i can learn a little bit :)

  • Glad to see you got it working! :)

    This is because of last step, changing Site and WordPress URL from Settings -> General.
    Site URL is URL what users type in browser to reach your site.
    WordPress URL is location where WordPress core files reside.

    When you changed URLs, it changed in database also and it "regenerated" links so it uses new installation.

    Changing The Site URL by WordPress Codex should explain you possible ways and what does it implies.

    USE wordpressclone; is SQL directive that defines active database. All queries in file will apply to that database. Basically that you forgot USE and ran file without it:

    • mysql -u root -p < ~/wordpress.sql

    It'll return something along: No database selected..
    You could also forgot that line and run:

    • mysql -u root -p -Dwordpressclone < ~/wordpress.sql

    It would work as -D or --database (same thing) specifies database to work on.
    Just to note don't run it again, so you don't lose new data in clone database, this is only for explanation purposes. :D

    I hope I explained you somewhat well this, if you need more help or have questions, feel free to ask, I will try to answer them ;)

Have another answer? Share your knowledge.