• You need 5 posts to download resources. You can only download 2 resources per day. To remove these limits consider upgrading.

XF How to duplicate a live site to use as a test site

Nick

Developer
Banned User
LV
0
 
Joined
Feb 7, 2023
Messages
491
Reaction score
128
Awards
14
 These instructions explain how to create a test installation which is an exact duplicate of your live installation.

On Your Server

  • Create a new test database with a different database name, user name and password to your live installation
  • Export your current live database and import it into your new test database
  • Create a new directory on your server, e.g. /test
  • Copy all of the files from your current live site directory to the new /test directory - ensure you also copy any hidden .htaccess files
  • Edit the the src/config.php file (library/config.php file if using XF1), in your new /test directory and change the database details to match your new test database
  • Update Options -> Basic options: Board title to something like Test MySite
  • Update Options -> Basic options: Board URL to match the new test URL
  • If you have XFES installed, to ensure it uses a different index from your live site, update the Index name in Options -> Enhanced search or just click on Reconfigure and save without entering a name and it will update to use the database name
  • If you are using a cache on your live site, update the new /test directory src/config.php file with a different cache prefix
  • Add the code below to the bottom of your new /test directory src/config.php file

Code:
$config['enableMail'] = false;

$config['cookie'] = array(
'prefix' => 'test_',
'path' => '/',
'domain' => ''
);


Don't forget that the test installation should be password protected to stop others from accessing it.

You can do that with .htaccess - copy the instructions here but apply it to the directory where the test installation is located instead:  Protecting admin.php and the install directory using .htaccess


On Your Computer (Localhost)

If you wish to duplicate your live installation on your PC, first you need to install a program such as XAMPP.
This comprehensive guide explains how to that: XF on localhost

Then the steps are very similar:

  • Create a test database with the same database name, user name and password as your live installation*
  • Export your current live database and import it into your new test database
  • Create a new directory on your computer to match your live site directory, if it is not installed in the root
  • Copy all of the files from your current live site directory to the same directory
  • Replace the .htaccess file with the following contents



Code:
Code:

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data|js|styles|install) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
  • Add the code below to the bottom of the new test installation config.php file

Code:
$config['enableMail'] = false;

$config['cookie'] = array(
'prefix' => 'test_',
'path' => '/',
'domain' => ''
);


*If you use root/root for the user name and password for XAMPP, then ensure you update the src/config.php file accordingly.

These are the actual steps I take when I update my local installation:
 

  1. Take a dump of the live database using mysqldump and then zip it

            1. mysqldump -u<user> -p<password> --single-transaction --skip-lock-tables db_name > /path/to/backup/db_name_$(date +%d.%m.%y).sql

            2. tar -czf db_name_$(date +%d.%m.%y).tar.gz /path/to/backup/db_name_$(date +%d.%m.%y).sql

2. Zip the entire installation directory

     1. tar -czf files_$(date +%d.%m.%y).tar.gz /path/to/install

3. Download the zipped database dump and files

4. Delete all existing files from my localhost installation directory

5. Extract the downloaded zipped files to my localhost installation directory

6. Update config.php with the localhost db details - db name, user, password

7. Drop the tables from the localhost db

8. Import the live db using

     1. mysql -uroot -proot db_name_dev <db.sql

if you need help just let me know!. this is all done. 

 
Last edited by a moderator:

Divo

Verified
LV
0
 
Joined
Mar 23, 2023
Messages
30
Reaction score
7
Age
26
Thanks for the share. This will definitely be very helpful for us.

 
Top