How to Create Magento Test & Production Sites
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.
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:
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:
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.
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”.
As for cPanel, database can be created by going to “DATABASES > MySQL 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.
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.
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”.