Start a conversation

Deploying & Scaling Magento Community Edition 1.8.x on Engine Yard

Updated: March 7th, 2014

This document is designed to help you install Magento on the Engine Yard platform, including optimization details and instructions for using add-ons with Magento.

Get started with Magento on Engine Yard

This document describes how to use Magento on Engine Yard.

Set up your Engine Yard environment

The great advantage with Engine Yard is the ability to quickly provision instances through our dashboard. This allows you to grow your store with the click of a button.

As a minimum we suggest a High CPU Medium 64 bit instance for the web server and the same for the database instance. This will work as a test environment, but will probably not support more than a couple dozen concurrent connections, especially with SSL enabled.

The UI provides a quick tutorial for those unfamiliar with Engine Yard.

Prerequisites

  • This article assumes you already have an Engine Yard account.
  • To use Magento in your Engine Yard environment, you must use the Engine Yard Gentoo 12.11 stack option (stable-v4).
  • Your environment must include other component versions as described in the Engine Yard Gentoo 12.11 Tech Stack.
  • You need to version control your Magento install with git and have your repository hosted and accessible. Hosted services like GitHub and Bitbucket make this very easy.

Install and configure Magento locally

You can install Magento on your Mac or Windows PC.

To install Magento on Mac OS X

  1. See the instructions in the official Magento docs: Magento Installation
  2. If you have problems, see the Troubleshooting section below.

To install Magento on Windows

  1. See the instructions in the official Magento docs: Magento Installation
  2. If you have problems, see the Troubleshooting section below.

Troubleshooting Magento Installation

This table contains troubleshooting tips related to Magento.

Symptom Solution
PHP Extensions "0" must be loaded error

This error appears after filling in the “Configuration” field. Complete the following steps:

  1. Navigate to: app/code/core/Mage/Install/etc/config.xml LINE 71.
  2. Replace:

    <extensions>
            <pdo_mysql/>
    </extensions>
    

    With:

    <extensions>
            <pdo_mysql>1</pdo_mysql>
    </extensions>
    
Exception Printing is Disabled error

The message “Magento install error - Exception printing is disabled - There has been an error processing your request. Exception printing is disabled by default for security reasons”. Make the following edit to allow Magento to print a more detailed explanation of your issue to the 'tmp' folder:

  1. Navigate to: /errors
  2. Rename: local.xml.sample to: local.xml
  3. Edit the file: magento/lib/Zend/Cache/Backend/File.php
  4. Replace:

    protected $_options = array(
         'cache_dir' => null,
         'file_locking' => true,
    

    With:

    protected $_options = array( 
         ‘cache_dir’ => ‘tmp/’,
         'file_locking' => true,
    
  5. Navigate to the root folder and create a new folder named: tmp. This is where your error logs will now be printed.

Migrate your existing Magento site

If you are migrating an existing Magento site, you will need to go through a few steps to ensure that you have a clean copy of your files, a backup of your database, and a proper workflow in place to successfully deploy your application to Engine Yard.

Warning: It is important that you do all this in a safe environment and not on your production server. Download a copy of your code base if you don’t have the most recent version locally.

Set up version control

As mentioned in the prerequisites, it is required that you use git to version control your application in order to deploy on Engine Yard. If you already use git or have your Magento project in a git repo already, you can skip to the Database backups section.

Initialize an empty git repository

  1. Open your console and navigate to the root directory of your Magento code base.

    cd ~/path/to/your/application
  2. Initialize a new git repository here so you can start tracking all your files using GitHub.

    git init
  3. Add a new file in your directory that will help us keep things clean and avoid tracking unnecessary files. This is done using a file called ‘gitignore’, which allows you to define rules for what should be ignored. Read more on this here: https://help.github.com/articles/ignoring-files

    touch .gitignore
  4. Open your newly created file in a text editor. You can use this Magento gitignore template as a starting point. Migrations are always a great time to do some housekeeping, so this will ensure that your code base becomes more lightweight and easier to maintain.

Track files and commit changes

Now that your repository has been set up, we can begin getting your local files to your online git repo. It is important to be able to track and commit changes to manage your project. To push your changes online, you will be using the ‘git add’, ‘git commit’ and ‘git push’.

  1. Add individual files to your staging area using git add yourFileHere.txt or add all using the command:

    git add --all
  2. Before you push your code base online, you need to commit it and include a meaningful message that describes any changes since the last iteration:

    git commit -m ‘my first commit’
  3. Finally you will need to create a remote repo to push your commits to. You will need the URL of your repo and enter:

    git remote add magento https://github.com/username/magento.git

    Where ‘magento’ is the name of your remote repo.

    git push magento master

    Which will push your project using the ‘magento’ remote repo to the branch of your project called ‘master’.

This will be your typical workflow; it encourages the best practices of establishing a local environment to work in before documenting your changes and pushing it to your live environment on Engine Yard.

Database backups

Be sure to make a backup of your current production database before copying it to use in your local Magento installation.

Deploy your app to Engine Yard

Import your database

The following documentation will guide you through the process of importing your Magento database. It’s important to note that this documentation assumes your database.sql has been compressed.

Restore or Load a Database

Note: One easy way is to use an app like Sequel Pro and run the query, depending on the size of the database. If the database is very big, this is not ideal and you should upload the database to the server before doing the import to avoid timeouts.

If you want to access your Magento database using an application like Sequel Pro or MySQL Workbench, you need to create an SSH Tunnel as outlined in the guide below.

Access Your Database Remotely Through an SSH Tunnel

Customize your environment

Custom PHP extensions

If there are custom PHP extensions that you would like to install on your deployment, you can do so using PEAR.

Custom Nginx

If your Magento application requires custom URL rewrite requirements, you might need to configure Nginx accordingly. See the following resources for examples and best practices:

Customize Nginx

Nginx HTTPRewriteModule

Custom Chef

Chef is an automation platform that allows you to configure, deploy, and scale your servers using code. For your Magento application, Chef provides a variety of options for easily customizing your cloud environment. See the following resources for examples and best practices:

Custom Chef Recipes: Examples and Best Practices

Customize Your Environment with Chef Recipes

Chef web site

Scale Magento on Engine Yard

Scaling Magento is where we look at creating a distributed infrastructure, separating some of the moving parts, allowing us to easily scale up as traffic/demand increases. Traditional setups, where Magento runs on a single server, make it difficult to scale like this.

Components we’ll look at separating are: the application, load balancing, database, session storage, caching, and asset storage.

The diagram below illustrates the Engine Yard model for scaling Magento applications in the cloud.

Scaling_Magento.png

Session storage

Magento provides two methods of session storage right out of the box: file system storage and database storage. Database storage supports a clustered environment and because we’re looking at a scalable solution, we want all application servers to be able to access shared session storage. Database storage also has better stability and durability in the event of a crash or reboot which makes it the ideal option.

If you select the database option during site configuration, Magento will store the sessions in MySQL. Because we’re looking to improve the performance and scalability, we’re going to store session data in a key-value store using Redis, which will make storing and retrieving sessions much faster.

Shared session storage with Redis

Redis is a popular key-value store ideal for session storage. We recommend using this to store sessions across multiple servers in your Magento application. Add your utility instance to your environment and give it a name, you will use this name in the code outlined below.

Navigate to /app/etc/local.xml and add the below code. Enter the name you chose for your utility instance as the host name.

<!-- SESSION STORAGE WITH REDIS -->

       <session_save>db</session_save>

       <redis_session>                     

           <host>HOSTNAME</host>

           <port>6379</port>

           <password></password>

           <timeout>2.5</timeout>    

           <persistent></persistent>

           <db>0</db>

           <compression_threshold>2048</compression_threshold>

           <compression_lib>gzip</compression_lib>

           <log_level>1</log_level>

           <max_concurrency>6</max_concurrency>

           <break_after_frontend>5</break_after_frontend>

           <break_after_adminhtml>30</break_after_adminhtml>

           <bot_lifetime>7200</bot_lifetime>

       </redis_session>

Caching

Front-end cache with Varnish

Varnish is a high performance HTTP accelerator designed to cache the contents of your application server. It can greatly increase the speeds in which your pages are delivered and reduce the weight on your server, thereby reducing the amount of servers needed overall.

You can install Varnish using one of the Engine Yard recipes included in the ey-cloud-recipes repo if you have it cloned to your local machine. The dedicated recipe is located here and the process of installing the cookbook required to run the recipes to install Varnish is here. Once installed, set up a utility instance (outlined here) and edit your /app/etc/local.xml file to include the name of your Varnish utility instance.

<!-- HTTP Reverse Proxy Caching WITH Varnish -->

       <cache>

           <backend>varnish</backend>

           <slow_backend>database</slow_backend>

           <id_prefix>cache_</id_prefix>

           <memcached>

               <servers>

                   <server1>

                       <host><![CDATA[HOSTNAME]]></host>

                       <port><![CDATA[11211]]></port>

                       <persistent><![CDATA[0]]></persistent>

                       <weight><![CDATA[1]]></weight>

                       <timeout><![CDATA[60]]></timeout>

                       <retry_interval><![CDATA[10]]></retry_interval>

                   </server1>

               </servers>

               <compression><![CDATA[0]]></compression>

               <cache_dir><![CDATA[]]></cache_dir>

               <hashed_directory_level><![CDATA[]]></hashed_directory_level>

               <hashed_directory_umask><![CDATA[]]></hashed_directory_umask>

               <file_name_prefix><![CDATA[]]></file_name_prefix>

           </memcached>

       </cache>

Back-end cache with Memcached

Memcached is an all-purpose distributed memory caching system that is cluster friendly, which allows it to scale with your application. We recommend using Memcached with your Magento application. If you prefer Redis, there is a second option for back-end caching using Redis.

You can find a dedicated Memcached recipe here:

https://github.com/jimneath/ey-memcached-util

Note: To get this to work, you will need update the memcached version in Jim Neath’s recipe. See:

https://github.com/jimneath/ey-memcached-util/pull/2

Code sample from /app/etc/local.xml:

<!-- BACKEND CACHING WITH MEMCACHED -->

       <cache>

           <backend>memcached</backend>

           <slow_backend>database</slow_backend>

           <id_prefix>cache_</id_prefix>

           <memcached>

               <servers>

                   <server1>

                       <host><![CDATA[HOSTNAME]]></host>

                       <port><![CDATA[11211]]></port>

                       <persistent><![CDATA[0]]></persistent>

                       <weight><![CDATA[1]]></weight>

                       <timeout><![CDATA[60]]></timeout>

                       <retry_interval><![CDATA[10]]></retry_interval>

                   </server1>

               </servers>

               <compression><![CDATA[0]]></compression>

               <cache_dir><![CDATA[]]></cache_dir>

               <hashed_directory_level><![CDATA[]]></hashed_directory_level>

               <hashed_directory_umask><![CDATA[]]></hashed_directory_umask>

               <file_name_prefix><![CDATA[]]></file_name_prefix>

           </memcached>

       </cache>

OpCode cache with APC

OpCode caches are a performance enhancing extension for PHP. They do this by injecting themselves into the execution life-cycle of PHP and caching the results of the compilation phase for later reuse. It is not uncommon to see a 3x performance increase just by enabling an OpCode cache.

Given that OpCode caches have almost no side-effects beyond extra memory usage (to store the cache), they should always be used in production environments. The Engine Yard PHP stack comes preconfigured with APC, so OpCode caching provides an additional performance boost out of the box.

Assets

Assets such as images and front-end code (JS, CSS) should be stored using a content delivery network (CDN). There are a variety of CDN options available and Amazon Web Services provides a Magento extension for their popular Cloudfront CDN.

Extend Magento on Engine Yard

The following are examples of add-on partners and their apps to extend Magento on Engine Yard.

Send email using SendGrid

SendGrid is a cloud-based email infrastructure that delivers email on behalf of companies, which increases deliverability and provides metrics around email communications. The SendGrid tools allow developers to send email from web applications through SMTP relay, SMTP API or Web API. SendGrid can be easily connected to your Magento application through the add-ons area of your Engine Yard deployment.

Note: Before using the SendGrid service, Magento must be configured for SMTP. See http://sendgrid.com/docs/Integrate/Open_Source_Apps/magento.html for more information.

Monitor apps using New Relic

New Relic is a leading SaaS (software as a service) provider of application performance management solutions that enable developers and operations teams to quickly and cost effectively monitor, troubleshoot, and tune application performance in real time. New Relic can be easily connected to your Magento application through the add-ons area of your Engine Yard deployment.

Load and performance test using Blitz.io

Blitz is a leading self-service cloud based load and performance testing platform. Built specifically for developers of API, cloud, web, and mobile applications; Blitz delivers unique capabilities to quickly and efficiently ensure performance and scalability. Blitz can be easily connected to your Magento application through the add-ons area of your Engine Yard deployment.

More information

This table provides other resources related to PHP and Magento.

For more information about... See...
Configuring and deploying an Engine Yard application in general Engine Yard Documentation (new UI)
Using PHP in the new Engine Yard UI Deploy Your PHP Application
Using PHP with Engine Yard Cloud (legacy UI) Deploy PHP App on Engine Yard Cloud
PHP Performance How To ... articles
Magento docs Magento Knowledge Base
Magento Installation Magento Install Guide

If you have feedback or questions about this page, add a comment below. If you need help, submit a ticket with Engine Yard Support.

_name_Scaling_Magento.png

  1. 84 KB
  2. View
  3. Download
Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Priyanka Bhotika

  2. Posted
  3. Updated

Comments