Make a Magento test site

MS SQL On Ubuntu 16.04

This has been lightly pinched from Wright Creative Labs. Credit where it’s due and all.


Once I have a new Magento site up and running, I always like to create a freshly copied test or development instance of the site. I use the development site to test out any new code, style, or configuration changes before applying them to the production server. Better safe than sorry, right?

So…

How to make a Magento test site.

I used to create the test instance as a subdomain on the production server. However, that approach can lead to easy mistakes, at least in my experience. When the paths are so close, it is easy to accidently wind up in the magento root rather than in the subdirectory. So, my preferred approach these days is to have a separate domain, say mytestserver.us, and have all of my dev servers on it. So, I may have one magento instance under mytestserver.us/site1 and another under mytestserver.us/site2. In my case, the production domain (let’s call it myprodserver.com, for example) and the dev server reside on the same VPS, so it is easy to copy files as needed via SSH.

When the production site is in a state that is ready to copy, here are the steps I take:

Decide on the location for the development instance files (where the magento test site is to be copied). In my case, I have a separate domain, mytestserver.us, and a subdirectory for each test instance. So, I login to my VPS via SSH and create a new subdirectory.

Copy the production server Magento files to the new test server subdirectory.

Create a new empty database on the testserver.
Create a data dump from the production database. The mySQL command is noted below. Replace the all caps items with your information.

Import the data dump previously created into the empty database on the test server. Replace the all caps items with the credentials for your new
test server database.

Next you’ll need to make some edits. In the test database, go to the coreconfigdata table and change the values of web/unsecure/baseurl and web/secure/baseurl to the test server url. E.g.  http://mytestserver.us/newtestsite/. I do not use an SSL certificate on my development servers, so the value for the unsecure and secure urls are the same. I make the edits using phpMyAdmin. Below is example SQL for the updates.

Clear cache files that were copied over from the production site.

Edit the local.xml file (app/etc/local.xml). Change the database values to point to the new test database host, database name, user, and password. If you are using a php cache such as apc, also remove or comment out the lines that use it. It is preferable not to have caching turned on in a development environment so all changes are reflected immediately.
You should now be able to navigate to the new test instance’s frontend and backend.
Go to the backend to make some further changes to the settings (e.g. http://mytestserver.us/newtestsite/admin/). The login is the same as the production instance.
Below are some of the items you may want to set differently for the development version of the site.

  • Turn on the store demo notice. System > Configuration > Design > HTML Head > Display Demo Store Notice.
  • Change email addresses used. For testing, you probably want emails to go to you or other developer, rather than the store owner. System > Configuration > Store Email Addresses and Sales Emails.
  • Turn off production payment methods. For example, you may want to either disable Paypal entirely, or put it in Sandbox mode. Likewise, you may want to turn on Check / Money Order, or other quick and easy payment method for testing order functionality.
  • Turn off SSL. Turn off Javascript file merging. System > Configuration > General > Web > Secure > Use Secure URLs in Frontend.
  • Turn off Google Analytics. System > Configuration > Google API > Google Analytics.
  • Turn off Javascript file merging. System > Configuration > Advanced > Developer > Javascript Settings. Also turn off CSS file merging if it was used.
  • Turn off Caching. System > Cache > Select All, then Disable. Also Flush Javascript/CSS Cache.
  • Rebuild indices. System > Index Management > Select all, then Rebuild.

You may also want to change the admin login or other accounts. System > Permissions > Users.

Also check your .htaccess file on the test instance to make sure that any production-only rewrite rules are removed or commented out. I also like to password protect the directory so that only allowed users have access. Below is an example of the code to add to your .htaccess file after you have set up the password (this is usually an option in your hosting control panel).

Edit your robots.txt file to keep search engine robots away.

That’s it! You now have a copy of your production Magento store ready for development and testing.

 

And that’s how you make a Magento test site.

2 thoughts on “Make a Magento test site

Comments are closed.