Cloud & DevOps in Magento 2: A Comprehensive Guide for Kiwi Commerce
Introduction
Cloud computing and DevOps practices are essential for optimising Magento 2’s performance, scalability, and reliability. Magento Cloud (now Adobe Commerce Cloud) provides built-in CI/CD pipelines and environment management for seamless deployments. This guide will cover key DevOps strategies, cloud hosting solutions, deployment automation, and real-world examples tailored for Kiwi Commerce.
Why Cloud & DevOps for Magento 2?
Magento 2 is resource-intensive, requiring a robust infrastructure to handle high traffic and ensure uptime. Cloud hosting combined with DevOps best practices offers the following benefits:
- Scalability: Automatically adjust resources based on demand, ensuring Magento 2 performs well even during traffic spikes.
- High Availability: Minimise downtime with redundant cloud environments, ensuring your store is always online.
- Faster Deployments: CI/CD automates releases and reduces manual errors, helping deploy changes faster.
- Cost Efficiency: Pay only for the resources you use, scaling as needed for peak traffic periods.
DevOps for Magento 2
Project Setup
Initialise a Magento Cloud Project:
To start, create a Magento Cloud project:
magento-cloud project:create –title=”My Store” –region=us –environments=3
- Define Services
Define the services such as Redis, MySQL, and Elasticsearch in .magento/services.yaml:
mysql:
type: mysql:10.2
disk: 2048
redis:
type: redis:5.0
- Configure Environments
- Use Git branches for staging, production, and other environments.
Customise .magento.app.yaml to specify build steps:
build:
flavor: none
commands:
php ./vendor/bin/ece-tools build:generate
Continuous Integration and Deployment (CI/CD)
- Trigger deployments on Git pushes.
- Add integration tests to your pipeline (e.g., PHPUnit, MFTF).
CI/CD Pipeline Flow
- Code Commit → Build → Staging Tests → Production Deployment
Real-World Case Study
A Kiwi retail company reduced deployment time by 70% using Magento Cloud’s pipelines. They automated testing in staging, validated with magento-cloud environments:test, and deployed to production with zero downtime.
Best Practices
- Use the magento-cloud CLI for environment snapshots and backups.
- Limit direct database changes in production; always use migration scripts.
Dockerising Magento 2: Local Development with Containers
Docker simplifies local development by containerising Magento, MySQL, Redis, and Elasticsearch.
Create docker-compose.yml
version: ‘3’
services:
app:
image: markoshust/magento-php:7.4-fpm
volumes:
– ./src:/var/www/html
depends_on:
– db
– redis
db:
image: mariadb:10.4
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: magento
redis:
image: redis:6.0-alpine
Build & Run
docker-compose up -d
docker exec -it <container_id> magento-installer
Sync Code
Mount the local src directory to the container for real-time updates.
Docker Architecture
By standardising development environments with Docker, a Kiwi team ensured that new developers could have Magento running in 10 minutes, bypassing manual PHP/MySQL setup.
Best Practices
- Use docker-compose.override.yml for environment-specific variables.
- Optimise Docker images with multi-stage builds to reduce size.
Monitoring with New Relic: Tracking Performance & Errors
New Relic provides real-time insights into Magento’s performance, errors, and database queries.
For Magento Cloud: Add to .magento.app.yaml:
runtime:
extensions:
– newrelic
Configure newrelic.ini:
newrelic.license = “YOUR_LICENSE_KEY”
newrelic.appname = “Magento 2 Store”
- Use APM to monitor checkout performance and create alerts for high error rates or slow response times.
Real-World Example
A Kiwi store identified a slow SQL query via New Relic’s Database tab, optimised it with indexing, and improved page load by 40%.
Best Practices
- Use New Relic Synthetics for uptime monitoring.
- Correlate PHP errors with deployments to identify breaking changes.
Infrastructure as Code (IaC) with Terraform
Automate cloud resource provisioning (AWS, GCP) using Terraform:
resource “aws_instance” “magento” {
ami = “ami-0abcdef1234567890”
instance_type = “t3.large”
tags = {
Name = “magento-web-server”
}
}
Real-World Use Case
A Kiwi company replicated production environments across regions in minutes using Terraform, ensuring disaster recovery readiness.
Security & Cost Optimisation
- Security: Use VPCs, security groups, and encrypted S3 buckets for media storage.
- Cost Control: Auto-scale instances during peak traffic; shut down dev environments overnight to save on costs.
Conclusion
By leveraging cloud technologies and DevOps practices, Magento 2 on the cloud provides better performance, lower costs, and scalability. With CI/CD, Terraform, and monitoring tools, you can build a robust eCommerce infrastructure for Kiwi Commerce that delivers a seamless experience and enhances operational efficiency.