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

Brogan

XenForo moderator
Staff member

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 /library/config.php file in your new /test directory and change the database details to match your new test database
  • Update Options -> Basic Board Information -> Board Title to something like Test MySite
  • Update Options -> Basic Board Information -> 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 admin.php?enhanced-search/ or just 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 /library/config.php file with a different cache prefix
  • Add the code below to the bottom of your new /test directory /library/config.php file
PHP:
$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 install is located instead: http://xenforo.com/community/resour...and-the-install-directory-using-htaccess.353/


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: http://xenforo.com/community/resources/how-to-install-xenforo-locally-to-your-pc-using-xampp.355/

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:
      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 /library/config.php file
    • PHP:
      $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 /library/config.php file accordingly.
 

Brogan

XenForo moderator
Staff member
I can't really help with so little information or context.

The Board URL in the option settings has zero effect on being able to log in to the ACP.
 

Brad P

Well-known member

Error​

SQL query:

-- --------------------------------------------------------

--
-- Table structure for table xf_session_install
--

CREATE TABLE xf_session_install (
session_id varbinary(32) NOT NULL,
session_data mediumblob NOT NULL,
expiry_date int(10) UNSIGNED NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4


MySQL said: Documentation
#1050 - Table 'xf_session_install' already exists

How can i fix the above?
 
I know this is going to be a real noobie question but I've followed the instructions and all I get are blank pages coming back, clearly a file is missing.

If I search for the url https://domainname.com/devtest/admin.php I get a blank screen not the ACP login in screen.

If I go through all the files in the devtest folder I get a blank screen except for asking for the .htaccess file which presents me with

Forbidden​

You don't have permission to access /devtest/.htaccess on this server.

Can anyone point me in the right direction please?
 

Brogan

XenForo moderator
Staff member
A blank screen could be a suppressed error.

Add this to the src/config.php file:

PHP:
ini_set('display_errors', true);

Other than that, it's difficult to say without access to the installation.
 
A blank screen could be a suppressed error.

Add this to the src/config.php file:

PHP:
ini_set('display_errors', true);

Other than that, it's difficult to say without access to the installation.
Thanks Brogan.

I added that line to the src/config.php file and then asked for the url ...../devtest/admin.php and at least it threw back something;

Fatal error: Uncaught XF\Db\Exception: Access denied for user 'ElSanto'@'%' to database 'Area51' in /home/perf/hp3-ph-1010337/770/3192770/user/htdocs/devtest/src/XF/Db/Mysqli/Adapter.php:165 Stack trace: #0 /home/perf/hp3-ph-1010337/770/3192770/user/htdocs/devtest/src/XF/Db/Mysqli/Adapter.php(28): XF\Db\Mysqli\Adapter->makeConnection(Array) #1 /home/perf/hp3-ph-1010337/770/3192770/user/htdocs/devtest/src/XF/Db/AbstractAdapter.php(60): XF\Db\Mysqli\Adapter->getConnection() #2 /home/perf/hp3-ph-1010337/770/3192770/user/htdocs/devtest/src/XF/Db/Mysqli/Adapter.php(113): XF\Db\AbstractAdapter->connect() #3 /home/perf/hp3-ph-1010337/770/3192770/user/htdocs/devtest/src/XF/Db/AbstractAdapter.php(516): XF\Db\Mysqli\Adapter->escapeString('options') #4 /home/perf/hp3-ph-1010337/770/3192770/user/htdocs/devtest/src/XF/Db/AbstractAdapter.php(494): XF\Db\AbstractAdapter->quote('options') #5 /home/perf/hp3-ph-1010337/770/3192770/user/htdocs/devtest/src/XF/DataRegistry.php(138): XF\Db\AbstractAdapter->quote(Array) #6 /home/perf/hp3-ph-101 in /home/perf/hp3-ph-1010337/770/3192770/user/htdocs/devtest/src/XF/Db/Mysqli/Adapter.php on line 165
 
The credentials in the config file don't match the DB user/password.
Hmmm, I've double and triple checked the details in the config.php file and they are definitely correct, if I apply the same details to MySQLWorkbench I can access the database no probs, same via my Host's control panel.

For what it's worth I've a config.php file and a config.php.default file, the latter being devoid of any of the DB details, just contains the code placeholders for them, ie.

  1. <?php
  2. $config['db']['host'] = 'localhost';
  3. $config['db']['port'] = 3306;
  4. $config['db']['username'] = '';
  5. $config['db']['password'] = '';
  6. $config['db']['dbname'] = '';
  7. $config['db']['socket'] = null;

  8. $config['fullUnicode'] = true;
 

Cassandra

Member
  • 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
Hi, can someone please explain how to do this exactly from cpanel?
I'm stuck here at the beginning.... thank you
 

Brogan

XenForo moderator
Staff member
Click on the MySQL Databases icon and create a new database and user.

Click on the phpMyAdmin icon and export and import the database or copy the existing database using the Operations tab.
 

Cassandra

Member
@Brogan thanks,

I followed the steps, but when I edited the test forum, I immediately saw that my edits affect my live site! o_O

I suspect it has something to do with my htaccess file, which I copied from my livesite, please could you advise what I should edit there? do I need to change the sitename.com/livesite to sitename.com/test in the test site's htaccess file?

In addition, I tried to password protect the test folder with cpanel, but it seems that this setting was overwritten by the htaccess?

# Mod_security can interfere with uploading of content such as attachments. If you
# cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
# SecFilterEngine Off
# SecFilterScanPOST Off
#</IfModule>
</IfModule>
# LS Cache
<IfModule LiteSpeed>
#CacheLookup public on
### LSCACHE START LOGIN COOKIE ###
RewriteRule .* - [E="cache-vary:xf_style_id,xf_language_id"]
### LSCACHE END LOGIN COOKIE ###
</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default

<IfModule mod_rewrite.c>
RewriteEngine On

# If you are having problems with the rewrite rules, remove the "#" from the
# line that begins "RewriteBase" below. You will also have to change the path
# of the rewrite to reflect the path to your XenForo installation.
RewriteBase /livesite
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.sitename.com/livesite/$1 [R=301,L]

# This line may be needed to enable WebDAV editing with PHP as a CGI.
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
 
Top