Magento Part 1 - Infrastructure & Hosting

<< Back to Magento Performance Tips for Scalability Homepage

Shared Hosting

Getting straight to the point - simply don't use it - ever :-) Magento requires tuning of your MySQL servers, your web servers, caching servers etc.. On a shared hosting environment you don't have access to these settings. Save yourself a lot of pain and setup your own infrastructure.

Recommended Infrastructure Setup

Setup your Magneto environment on AWS (Amazon Web Services). It's extremely cost effective and if you follow the below guidelines you can scale up your servers as your server load increases over time.

Route32 for DNS

Why? Because it is super simple to setup, easy to maintain, has redundancy and is really cheap!

EC2 & Load Balancer for Front-end web servers

You will want to run at least 2x EC2 front-end servers for your Magento website both sitting behind a load balancer.

"Load balancers allow you to run multiple front-end (Apache/PHP) servers for your Magento installation. They are great for performance, redundancy and for creating downtime free releases."

  1. Setup 2x medium instance web servers for your Apache/PHP/Magento codebase.
  2. You will want to use EC2 servers that have at least 2 CPUs (Magento in most cases will perform much better with more CPU power than memory).
  3. Setup the 2 servers identically (look into CloudFormation if you want to automate this).
  4. Now setup 1 load balancer for your 2 front-end servers.
  5. Add your 2 front-end servers to your load balancer (You will need to setup a polling end-point so the load balancers know the server is in service). It could be as simple as having a PHP file in the root directory like below:

    <?php var_dump($_SERVER['REMOTE_ADDR']); ?>

    In your Amazon Load Balancer your health check should look something like:

EC2 & Load Balancer for admin web servers

It is good practice to run your Magento admin on its own servers. This will ensure that your staff and admin users wont affect your front-end website if using Magento admin heavily. It also allows you to add a layer of security to your Magento admin (and lock it down to just your office network).
    1. Setup 2x medium instance admin web servers (these can be identical to your front-end web servers) for your Apache/PHP and magneto codebase.
    2. Again, you will want to use EC2 servers that have at least 2 CPUs.
    3. Setup the 2 servers identically.
    4. Now setup 1 new load balancer for your 2 admin servers.
    5. Add your 2 admin servers to your load balancer (like you did you front-end servers).

    RDS for your database

    You will want to run your database on a separate server to your admin and front-end servers. This will give you much better performance and decouple your application servers from your database (good for scaling).
    1. Setup 1x medium RDS instance for your database.
    2. Import your initial MySQL database dump to this database.
    3. You will want to leverage the power of MySQL replication for your Magento website, so within the RDS configuration of your database above, create a 'read replica'.
    4. This way you can share the load of your MySQL queries over both of your databases (more details about how to configure Magento for read replica in Part 3 - MySQL setup and performance).

    Elastic Cache

    Magento needs cache for it to support even just a few users efficiently. 
    1. Setup an elastic cache instance (Redis), or setup Memcache on your front-end and admin servers.
    2. Configure Magento to use this caching service
    3. More details about how to configure Magento for caching in Part 6 - Magento Caching.

    CloudFront CDN for product images

    Using a CDN allows you to offload a lot of static resources (like product images, CSS, Javascript etc...) to CDN servers all around the world. This will free up your server resources.
    1. Setup a CloudFront distribution within AWS.
    2. This will give you a URL like:
      that we can configure later in Magento to serve content from.
      Part 2 explains how to setup CDN within Magento

    SES for transactional emails

    Your Magento website will send out transactional emails (contact form emails, order emails etc...). You may as well keep this on AWS with simplicity.
    1. Setup SES within AWS.
    2. You will need to configure your domain, and allowed senders.
    3. You will also have to apply for production use (which can take up to 48 hours). Make sure you do this a few days before launch.

    Reserved instances

    You can dramatically reduce your AWS costs by purchasing reserved instances. You should purchase 'heavy utilisation' reserved instances for all of your EC2 and RDS instances (your costs will be about 1/3 to 1/2 of the costs of not purchasing reserved instances).

    Part 2 - Prepare for Scalability


    Post a Comment