We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

Tutorials
More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsCMS TutorialsMagentoMagento Website Setup

How to Create Magento Test & Production Sites

KVM VPS
Brazil VPS
USA VPS
OpenVZ VPS
Linux Cloud Server
Germany Cloud Servers
Windows Cloud Server
Ubuntu VPS
Linux KVM Hosting
cPanel KVM

When it comes to developing an enterprise website for a client or just starting an online shopping website, usually it is a good idea to have both testing and production environments. The reason why we need such set-up is that we could use the testing environment to install or update features, designs and content and have it accessible by you and your team for any further development or feedback. When it is fully working and ready, deploy the updates to the live (production) site. This way we can avoid any unexpected errors and confusions from the user side and have an efficient, risk-free way to develop your site.

In this tutorial we assume we already have Magento installed in our hosting account or server. In this case, we can start preparing the test environment. Please note that in order to do so we will need full access to the Magento installation directory. We recommend using SSH client, but it also works through file manager or FTP client.

Follow these steps to create Magento test and production sites

Start with connecting to your hosting account and navigating to Magento installation directory. Then create a folder in the public_html directory where Magento is hosted. This sub-folder will be used for the test website/environment. SSH commands would be as follows:

1
2
cd /home/username/domains/domain.com/public_html/
mkdir test

The next step is to copy all Magento files from public_html directory to the newly created “test” folder. We can use the commands below:

1
cp -r /home/username/domains/domain.com/public_html/* /home/username/domains/domain.com/public_html/test/

Please note, the command above will copy folders and files except for .htaccess file. To copy .htaccess, we may use the following command.

1
cp /home/username/domains/domain.com/public_html/.htaccess /home/username/domains/domain.com/public_html/test/

Since the test environment will use a separate database, we need to create a database as well. This can be done in the control panel of your hosting account. For example, in DirectAdmin database can be created by clicking on “MySQL Management”.

mageto - DA

As for cPanel, database can be created by going to “DATABASES > MySQL DATABASES”.

databases

Now we need to export the database from the current Magento installation. In order to do that, we may use MySQL client like phpMyAdmin. Simply login to phpMyAdmin and find the required database. Then click on “Export” tab and export the database with all the tables.

Now import the tables to the newly created database. Go to phpMyAdmin and open the database that will be used for our testing environment (right now it should not have any tables). Then click on “Import” tab and select exported MySQL file for importing. Once it is imported, it should look identical to the original database.

The alternative SSH commands for exporting and importing the database are as follows.

1
2
mysqldump -h hostname -u database_username -pdatabase_password database_name > database.sql
mysql -h hostname -u database_username -pdatabase_password database_name < database.sql

In this case, we have to make sure the new database has different name, username and password. Also, database details should be updated with the new one in the file “app/etc/local.xml”.

Now we need to adjust the settings in the database for the testing environment. Once again, access the database and open table named “core_config_data”. There we need to adjust links for 2 records. Find the first one in the line with “web/unsecure/base_url” and replace its value to “http://www.domain.com/test/”. Do the same for another record that has “web/secure/base_url” path. If you would like to use a SQL command, it should look as follows.

1
2
UPDATE core_config_data SET value="http://www.domain.com/test/" WHERE path=’web/secure/base_url’;
UPDATE core_config_data SET value="http://www.domain.com/test/" WHERE path=’web/unsecure/base_url’;

The final step is to clear cache files from the copied website files. They should be located in directory “/home/username/domains/domain.com/public_html/test/var/”. After completing all the steps, we should be able to access test website by going to “yourdomain.com/test”.

USA VPS
Germany Cloud Servers
cPanel KVM
OpenVZ VPS
Linux Cloud Server
Windows Cloud Server
Linux KVM Hosting
Brazil VPS
KVM VPS
Ubuntu VPS
Rate this Tutorial:
2 Comments Leave a Comment
  1. Nile Aagard

    There is a typo in this article:
    In step 4, the ssh commands the author is referring to should contain the piping commands ‘>’ and ‘<' instead of '>' and '<'. It would seem that this error is from the expectation that the symbols themselves would not process correctly because they are reserved for HTML when in reality somewhere along the line the browser was instructed to present those lines as pre-formated text.
    This is important to note because Bash will not understand the HTML escapes and will throw errors when executing these commands exactly as presented.

    Reply
  2. Rajiv

    To copy database using phpmyadmin, you can follow these steps:

    Begin by accessing phpMyAdmin via cPanel or Plesk.

    – Select the database you wish to copy (by clicking on the database from the phpMyAdmin home screen).
    – Once inside the database, select the Operations tab.
    – Scroll down to the section where it says “Copy database to:”
    – Type in the name of the new database.
    – Select “structure and data” to copy everything. Alternately, you can select “Structure only” if you want the columns but not the data.
    – Check the box “CREATE DATABASE before copying” to create a new database.
    – Check the box “Add AUTO_INCREMENT value.”
    – Click on the Go button to proceed.
    – If you click on the home icon, you will notice your new database listed in the left column. If you go inside, you will see the database is a copy of the previous database.

    Reply
Leave a Comment