titanium
By:
titanium

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 153 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 :)

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.

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.