Implementing Hybrid Hosting Model

In previous post I’ve introduced concept of hybrid model which allows to scale web applications, such as magento, horizontally with a minimum effort and investments. And now I’d like to show you quick implementation example.


Network Diagram

Requirements

Here is services we’re going to use for our setup, as per original diagram:

  • PaaS - Heroku
  • Traditional Server - DigitalOcean VPS
  • Magento 2 - DigitalOcean One-Click App (Magento 2.0.7 CE on 14.04)
  • CDN - Amazon CloudFront (any should work)

Setup and Deploy to PaaS

First of all we need to turn our Traditional Server and Magento application into hybrid mode, such as enabling MySQL to listen on external port, tweaking magento configuration and putting everything into GIT SCM.

For simplicity purposes I’ve wrapped all steps into set of scripts which we’re going to use here, so, let’s login into our VPS and run the following commands:

1
2
3
4
git clone git@github.com:yevgenko/magento-heroku-setup.git
cd magento-heroku-setup
source env.sh
make

The next step is deployment to Heroku PaaS. While on VPS, run the following commands:

1
2
3
4
cd $MAGENTO_PATH
heroku login
heroku create --region frankfurt
git push heroku master

Finally update DNS records and magento URL configurations accordingly. Please see more details below, in “Magento URLs configuration” section.

Magento URLs configuration

This section describes which DNS and URL configuration need be updated in order to finalize our setup, i.e. to make it transparent to web site visitors.

Admin URL

Create A record pointing to the IP address of our traditional server, for example admin.megashop.com.

Once done, update magento admin URL accordingly via Magento admin site:

Stores -> Configuration -> Advanced -> Admin Base Url
Use Custom Admin URL: YES
Custom Admin URL: admin.megashop.com

Source Origin for CDN

Create another A record pointing to the same IP of our traditional server, but name it clearly for CDN purposes, e.g. assets.megashop.com.

Once done, update CDN provider, in our case CloudFront, to pull data from the assets.megashop.com instead of primary domain.

Main Web Store Domain

Point your primary domain, such as www.megashop.com, to heroku application domain, for example to megashop.herokuapp.com. Normally we could use CNAME, but in some cases you might prefer A records, please see heroku guide for more details.

Conclusion

That’s it, we’ve done very basic setup to start evaluating hybrid hosting model.

There still a room for improvements, such as moving sensitive data out of GIT SCM, enabling monitoring addon on heroku and most important understand the metrics it collects, hopefully I’ll cover those in next posts.

Please let me know if there is anything also you’d like me to cover more in depth.

Comments