Setting up Magento Staging Stores on Sonassi Magestack

Setting up a staging store is a great way to test new extensions and updates without risk of damage or downtime to the live store. This guide will run through all of the steps involved on Sonassi’s Magestack but the process is similar for other systems.


Copy webserver files

First off, log in to the Sonassi web server via SSH

ssh [email protected]

Create the directory for the site

mkdir /cloud/domains/staging.domain.com

Copy the current live file structure to the staging directory

cp -R /cloud/domains/domain.com /cloud/domains/staging.domain.com


Copy database

Log in to phpMyAdmin at

phpmyadmin.magestack.com

Navigate to the relevant table and select the Operations tab

Under Copy database to enter a name for the new database (domain_staging or similar recommended)

Accept the default values and select Go


Create a new database user

Select the table you have just created, select the Privileges tab and Add User

Give the user an appropriate name (same name as table is recommended)

Add your web server address or wildcard on your subnet (i.e 192.168.0.%) in the hostname field

Generate a password and add it to the clipboard

Accept the defaults and click Go


Point the site at the staging database

Log in through SFTP, navigate to and open

/cloud/domains/staging.domain.com/http/app/etc/local.xml

Database connection credentials start at around line 40. Add the username, password and database name here.

At approximately lines 60 and 80 there is an integer value under tags. Change this to the same value. This value should be unique (i.e. not used for other sites) and also greater than 2 but less than 16

Save and close this file


Confirm Redis value is unique

Log in to the web server again via SSH

ssh [email protected]

Run the following script

/cloud/scripts_ro/redis_db_identify.sh

If d is displayed by any sites they do not have unique Redis IDs and these should be changed immediately


Modify admin base URL

Log in to phpMyAdmin at phpmyadmin.magestack.com

Navigate to the relevant staging table and select the Search tab

Search for the string %oldadmin.domain.com%

Click Select All under Inside tables: then Go

cmd/ctrl + F and search for the string browse

URLs are defined in the core_config_data table

Click edit and change the value to something more appropriate (example: http://staging.domain.com)


Restrict access to external IP addresses

Login with your SFTP client and navigate to

/cloud/domains/staging.domain.com/___general

Create/open the file staging.domain.conf

If the file has any content, delete is all and replace with

allow your_ip_address;
deny all;

This will require an Nginx restart to take effect


Restarting Nginx

In an Internet browser, go to mmonit.magestack.com and click the Status tab

Select the web1.cxxx.sonassihosting.com node

Select the Nginx process not file and click restart

To test, visit a proxy of your choice (this will mask your IP) and attempt to visit the staging store with restricted access. You should see 403 Forbidden


Run a store in a subdirectory

Log in to the web server through SSH

ssh [email protected]

Navigate to the staging domain

cd /cloud/domains/domain.com/http

Create and enter a directory for our new store

mkdir examplessite

cd examplesite

Create symbolic links between our core Magento files and the examplesite store

ls ../ | while read FILE; do
ln -s ../$FILE .
done
rm index.php
cp ../index.php .


Configuration of a store to run in subdirectory

In your SFTP client, navigate to

/cloud/domains/staging.domain.com/___general

Open staging.domain.conf

Here is an example configuration for a store located in the folder /http/bg2015

location ~* ^/examplesite {
location ~* .(php) {
set $my_mage_run_code "examplesite";
set $my_mage_run_type "store";
include fastcgi_params;
}
try_files $uri $uri/ /examplesite/index.php$is_args$args;
}


DNS for staging stores

Visit http://sms-sagat.theclientarea.info

Click Menu then Dns

Select the domain in question then modify and existing A record alias or, if none exists, create a new one

Here is an example configuration-

A record - alias - staging.domain.com - webserver.ip.address.here - 86400

Leave a Reply

Your email address will not be published. Required fields are marked *