Copy Production Store

  1. Login to SSH and go to the Document Root for the staging directory

    cd staging
  2. Copy all data from the live site to the staging directory

    cp -R ../public_html/* ../public_html/.htaccess .
  3. Copy production database to staging database

    mysqldump -u PRODUCTION_DBUSER -p PRODUCTION_DBNAME > data.sql
    mysql -u STAGING_DBUSER -p STAGING_DBNAME < data.sql
  4. Change credentials to store staging database configuration in:

    ~/staging/app/etc/local.xml
  5. Run the following sql query on the staging database and update the values to point to the staging url:

    SELECT * FROM `core_config_data` WHERE `path` LIKE '%base_url%';

Update (7/21/2011): Git

Not sure why it took me this long to finally get the Tech And House site on Git, but finally did it today. I’m currently versioning just the app and skin folders and the themes that are in use, everything else has been placed in .gitignore. Since the staging domain is on the same server as the production domain, my hosting provider flips and disables my backups because I’m not allowed to have that many files on the server. I have to make my updates on dev, test on staging and right after pushing to production, I need to clear out my staging server. If you’re in this boat, here are the steps I follow:

Steps on Staging Server:

  1. Make changes on development box, git commit, git push
  2. Prep staging server by pulling production code to staging folder
    cp -R ../public_html/* ../public_html/.htaccess .
  3. Since we keep deleting all the files on the staging server, reset it to the last committed state of the git repo:
    git reset --hard HEAD
  4. Pull changes that were made on the development machine:
    git pull
  5. Set permissions and clear cache and sessions
    find . -type f -exec chmod 644 {} \;
    find . -type d -exec chmod 755 {} \;
    chmod o+w var var/.htaccess includes includes/config.php app/etc
    chmod -R o+w media
    chmod -R 755 var
    rm -rf var/cache
    rm -rf var/session
    chmod 550 mage
    chmod 550 pear
    #chmod 550 pear Magento <= 1.5 chmod 550 mage for Magento >= 1.5
  6. Update database connection details to point to the staging servers db: /app/etc/local.xml

Maybe “Update 2″ will have Capistrano involved handling the deploy as well, but for now, I’m ok with this little setup. Usually just skip staging all together as thats the most time consuming process due to hosting providers TOS. Change/Test on dev, git pull straight to production.