Deploy AWS Magento 2 on Ubuntu for Open Source E-Commerce

Deploy AWS Magento 2 on Ubuntu for Open Source E-Commerce

Are you looking to harness the power of AWS for your online store? AWS Magento 2 combines Magento's flexibility with its scalability.

This tutorial will cover the step-by-step process of deploying Magento 2 on AWS.

Best Magento Hosting now

Key Takeaways

  • Steps to set up the necessary infrastructure and configure services.
  • Performance optimization to simplify deploying your online store on AWS for all users.
  • Magento's eCommerce capabilities with AWS's scalable cloud infrastructure.
  • Installing necessary software, including MySQL, PHP, and a web server.
  • Advanced methods to set up an AWS account and launch an EC2 instance.
  • Magento's built-in tools and AWS's solid features deliver exceptional performance.
  • Troubleshooting common issues when configuring and optimizing your store on AWS.

Why Install Magento 2 on AWS Cloud Templates?

The Magento reference architecture includes CloudFormation templates. They are designed to deploy Magento Community Edition on the AWS Cloud.

Magento is an open-source content management system for eCommerce websites. These templates can be used to deploy Magento. This automated setup creates a cluster running Magento. It comes with optional sample data to help you explore custom themes and test the web store.

This architecture offers two deployment options, including:

  • Building a new AWS infrastructure for your Magento stack
  • Integrating Magento into your existing AWS setup

The system leverages the following:

  • MySQL on Amazon RDS for database operations
  • Amazon EFS for shared storage across EC2 instances
  • Amazon ElastiCache cluster with Redis to enhance application load times

The deployment also includes the Amazon Pay plugin pre-installed.

Using the provided AWS CloudFormation templates, you can deploy a fully configured Magento infrastructure in your AWS account. Key features of this architecture include:

  • Deploying Magento Community Edition into a "new VPC"
  • Deploying Magento Community Edition into an "existing VPC"

These templates can also serve as a foundation for your customized implementation.

Strategies to Create a Scalable Magento2 Store Using AWS Services for Routing Traffic

Service Component Primary Function Scalability Benefits Implementation Impact Performance Metrics
Route 53 DNS Management Global traffic routing Reduced latency; improved availability Supports 250,000+ retailers
CloudFront Content Delivery Static content caching Faster page loads worldwide Multi-billion dollar operations
Application Load Balancer Traffic Distribution Content-based routing Handles millions of requests Automatic load redistribution
Auto Scaling Groups Resource Management Dynamic capacity adjustment Automatic traffic handling Handles 250,000+ retailers
ElastiCache (Redis) Session Management Improved response times Reduced database load Multi-billion dollar operations
RDS Database Operations Automated scaling High performance for catalogs Automatic load redistribution
S3 Media Storage Unlimited storage capacity Efficient content delivery Handles 250,000+ retailers
EC2 Instances Computing Resources Flexible resource allocation On-demand scaling Multi-billion dollar operations
Elastic Load Balancing Load Distribution Cross-zone balancing High availability across zones Automatic load redistribution
CloudWatch Performance Monitoring Resource optimization Real-time scaling decisions Handles 250,000+ retailers

AWS Marketplace: Magento User Performance Optimization

1. Core AWS Infrastructure

i. Instance Selection

  • Choose EC2 instances with Graviton processors for optimal PHP performance.
  • Configure Amazon RDS or Aurora for database scalability.
  • Implement ElastiCache for session management and caching.

ii. Network Architecture

  • Deploy CloudFront CDN to reduce global latency.
  • Set up Elastic Load Balancing for traffic distribution.
  • Enable HTTP/2 on web servers for improved connection handling.

2. Advanced Caching Strategies

i. Multi-Layer Caching

  • Configure Varnish Cache for full-page caching.
  • Implement Redis for session storage and database caching.
  • Enable browser caching for static assets.

ii. Content Optimization

  • Minimize CSS and JavaScript files.
  • Implement image compression without quality loss.
  • Configure ElasticSearch query cache for faster product searches.

3. AWS Auto Scaling Configuration for Database Performance Tuning

auto Scaling configuration in aws for magento 2 to optimize database performance with scalable resources

i. Resource Management

  • Set up Auto Scaling groups for EC2 instances.
  • Configure CloudWatch alarms for scaling triggers.
  • Implement multicast replication for data consistency.

ii. Optimization Techniques

  • Use Amazon Aurora in Magento to enhance MySQL performance.
  • Implement proper indexing and query optimization.
  • Configure read replicas for scaling read operations.

iii. AWS Security Features

  • Enable AWS Shield for DDoS protection.
  • Implement IAM roles for access control.
  • Configure security groups and network ACLs.

Domain Names and DNS Public IP Addresses in Amazon Web Services Documentation

DNS Component Format Usage Resolution Behavior Business Benefits
Private DNS Hostname ip-172-31-19-128.ec2.internal (US-East-1) Internal VPC communication Resolves to private IP within VPC Enhanced security control
Public DNS Hostname ec2-54-147-16-116.compute-1.amazonaws.com External access Resolves to public IP outside VPC Reliable DNS resolution
Custom Domain example.com Branded access Configurable via DHCP options Professional branding and identity
VPC DNS Attributes enableDnsHostnames, enableDnsSupport DNS functionality Controls hostname assignment Enhanced security control
Public IPv4 DNS ec2-public-ip.region.compute.amazonaws.com External routing Resolves to private IP internally Consistent global access
Elastic IP DNS Static DNS hostname Production environments Consistent addressing Reliable DNS resolution
Route 53 Integration Custom domain routing Global traffic management High availability routing Professional branding and identity
Instance DNS Resolution Public/Private resolution Cross-VPC communication Based on network location Consistent global access

AWS Server Architecture for Magento eCommerce Deployment

aws server architecture for magento eCommerce, featuring cloudfront, ec2, rds, and elastiCache for enhanced scalability and performance

  1. Amazon CloudFront: Acts as a Content Delivery Network (CDN). It accelerates the delivery of static and dynamic web content.

  2. Elastic Load Balancing (Application Load Balancer):

  • First Load Balancer: Distributes incoming traffic across Varnish instances. They are deployed in an AWS Auto Scaling group across multiple Availability Zones.
  • Second Load Balancer: Balances traffic from Varnish Cache to Magento instances. It works in an Auto Scaling group across multiple Availability Zones.
  1. Varnish Cache on Amazon EC2: Deployed as a caching HTTP reverse proxy to accelerate web applications. It efficiently handles traffic from the first Load Balancer to the Magento servers.

  2. Magento Web Servers: Hosted on Amazon EC2 instances within private subnets for secure operations.

  3. Amazon OpenSearch Service: Provides strong catalog search capabilities for Magento.

  4. Amazon ElastiCache: Uses the Redis cache engine, deployed within private subnets. It enhances data retrieval speed and application performance.

  5. Database Options: For high availability, a secondary database synchronously replicates in a separate subnet using the Multi-AZ deployment option. Amazon RDS for MySQL or Amazon Aurora is deployed via Amazon RDS in private subnets.

  6. Amazon S3 is used as remote storage for Magento web servers. Hosting shared media helps users access files securely and efficiently.

  7. Amazon MQ (Optional): Acts as a message broker to manage asynchronous communication. The Message Queue Framework (MQF) enables efficient handling of bulk operations like:

  • Importing/exporting data
  • Mass price updates
  • Assigning products to warehouses

Note: Messages for bulk tasks are queued and processed by background consumers.

Magento App Marketplace Access and MySQL Server Security with AWS Nginx

Security Component Configuration Implementation Details
MySQL Root Access Restricted Access Disable root login via phpMyAdmin, which requires specific user credentials.
User Authentication Multi-layered Configure HTTP authentication with Nginx and implement password validation.
Database Users Role-Based Create separate users with specific permissions for different functions.
SSH Security Key-Based Access Generate a dedicated SSH key pair for EC2 instance access.
Network Security IP Restrictions Configure security groups to allow specific IP ranges.
SSL/TLS Encryption Enable SSL for all database connections and admin access.
Firewall Rules Port Control Restrict access to port "3306" for MySQL and port "80/443" for web traffic.
Access Control Role-Based Implement Project Admin and Project Viewer roles.
Environment Access Tiered Permissions Configure separate access levels for production, staging, and development.
Static IP Elastic IP Assign static IP for consistent access and DNS configuration.
Backup Security Encrypted Storage Use Amazon S3 in Magento 2 with encryption for backup storage.
Database Monitoring CloudWatch Configure alerts for unauthorized access attempts.
Application Users Restricted Privileges Create specific user roles with minimum required permissions.
Connection Security VPC Configuration Use VPC security groups to control instance connections.

10 Steps to Deploy a Magento Stack Using AWS for eCommerce Store Hosting

Step 1: Configure Prerequisites

  • AWS Account: Create an AWS account (requires credit/debit card for verification).
  • Tools: CLI (e.g., GitBash), VIM/NANO, and an Adobe Commerce account.
  • Optional: Route53 for domain management, Elastic IP, and a custom domain.

Step 2: Set up the AWS EC2 Instance

  1. Login to your AWS account and navigate to the EC2 dashboard.
  2. Launch Instance: Click "Launch Instances" and select 'Ubuntu 20.04 (64-bit)'.

setting up an aws ec2 instance with ubuntu server 20.04 for deploying magento 2 eCommerce

  1. Choose the "t2.micro" instance type for free-tier eligibility.
  2. Configure default settings and change storage to "30 GiB".
  3. Set up a 'Security Group'.
  4. Add rules for HTTP and HTTPS with the source as "Anywhere".

configuring http and https rules in aws security group for secure magento 2 operations

  1. Click the 'Launch Instance' button to create and download the key pair to access the server.

launching an aws ec2 instance for magento 2 deployment with key pair setup for secure access

Step 3: Connect to the Instance

  1. Access the instance remotely using SSH.

Note: Use the downloaded .pem file.

  1. Update and upgrade the server using the following commands:

sudo apt update sudo apt upgrade

Step 4: Create SWAP Memory

  1. Create a SWAP file to meet Magento's 2 GiB requirement.
  2. Run the following commands:

sudo fallocate -l 4G /swap.img sudo chmod 600 /swap.img sudo mkswap /swap.img sudo swapon /swap.img echo 'swap.img none swap sw 0 0' | sudo tee -a /etc/fstab

Step 5: Install Software

  1. Install Apache, MySQL, and PHP using this command:

sudo apt install apache2 mysql-server php7.4 php7.4-curl php7.4-soap php7.4-bcmath

  1. Verify installations using the following commands:

apache2 -v mysql -V php -v

Step 6: Configure MySQL

  1. Secure MySQL installation using the command given below:

sudo mysql_secure_installation

  1. Create a database and user for Magento using the following commands:

CREATE DATABASE magento2; CREATE USER 'magento2user'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON magento2.* TO 'magento2user'@'localhost';

Step 7: Install Elasticsearch

  1. Download and install Elasticsearch.
  2. Run the following commands:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.2-amd64.deb sudo dpkg -i elasticsearch-7.10.2-amd64.deb sudo systemctl start elasticsearch sudo systemctl enable elasticsearch

Step 8: Install Magento 2

  1. Download Magento using Composer:

sudo composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition .

  1. Set directory permissions:

sudo chmod -R 777 var/ pub/ generated/

Step 9: Configure Magento

  1. Set up Magento using CLI:

php bin/magento setup:install --base-url=<your_URL> --db-name=magento2 --db-user=magento2user --db-password=password --admin-user=admin --admin-password=admin123

  1. Change the root of the document to /pub in Apache configuration.

Step 10: Optimize and Launch

  1. Enable production mode and flush the cache using the following commands:

php bin/magento deploy:mode:set production php bin/magento cache:flush

  1. Test the website by accessing the instance’s public IP in a browser.
  2. Disable Two-Factor Authentication to access the admin panel:

php bin/magento module:disable Magento_TwoFactorAuth

  1. Access the admin panel via <your_URL>.com/admin.

Note:

  • Optional steps for custom domains (Route53) and Elastic IPs can enhance functionality.
  • Ensure all permissions and configurations are accurate to avoid errors.

How to Choose the Right AWS Instance for Magento File System Management?

Instance Type Specifications Best Use Case Performance Impact Cache Operations CPU/Memory Impact Auto-scaling Benefits
C5.xlarge 4 vCPU, 8GB RAM High-traffic stores 2.5s page load times Cache flush: 50s Stable CPU, efficient memory Handles traffic spikes effectively
M4.large 2 vCPU, 8GB RAM Development/Testing 6.6s page load times Cache flush: 3.5m Variable CPU under load Limited scaling capability
R5/R6g High Memory, AWS Graviton2 Database-intensive operations Optimal for large catalogs Fast cache operations Excellent memory management Ideal for variable workloads
T3/M5 Balanced resources Small-medium stores Cost-effective performance Moderate cache times Balanced CPU/memory usage Good scaling flexibility
C5/R5 High CPU/Memory Large-scale deployments Enhanced computing capacity Quick cache response Superior CPU performance Excellent scaling potential

How Does AWS Support with Magento Open Source Software Deliver Ecommerce Capabilities?

1. AWS Service Integration

integration of aws services like ec2, rds, and elasticache for scalable magento 2 operations

  • EC2 instances power the Magento application servers.
  • RDS manages database operations for product and customer data.
  • ElastiCache with Redis improves application load times.
  • CloudFront ensures faster content delivery worldwide.

2. Automated Infrastructure

  • Auto Scaling monitors CPU utilization and memory usage patterns.
  • Load balancing distributes traffic effectively.
  • Multi-AZ deployment ensures high availability.
  • NAT gateways enable secure outbound connectivity.

3. Enhanced Speed and Reliability

  • Global CDN network reduces latency and automatically compresses objects/images for different devices.
  • Database query caching improves response times.
  • ElastiCache with Redis stores database query results for frequently accessed products.
  • Automated backups protect sensitive data.
  • Elastic IP addresses ensure stable DNS resolution.

4. Detailed Protection

  • AWS Shield provides DDoS protection.
  • IAM roles control access permissions.
  • Security groups act as virtual firewalls at the instance level.
  • Network ACLs provide subnet-level security with stateless filtering.
  • The combined approach creates defense-in-depth with multiple security layers.
  • SSL/TLS certificates secure transactions.

5. Growth Support

  • Handles increased traffic volumes smoothly.
  • Supports expanding product catalogs.
  • Enables multi-store management.
  • Provides flexible resource allocation.

FAQs

1. How do I set up PHP with Elasticsearch on Ubuntu Server 20.04?

First, install Elasticsearch in Magento 2 using its package. Then, install PHP 7.4 with the required extensions, such as php7.4-curl, php7.4-soap, and php7.4-bcmath. Ensure both services are running on Ubuntu Server 20.04.

2. What is the default user name for AWS Ubuntu instances?

The default user name for Ubuntu instances on AWS is Ubuntu. Use this while accessing instances via SSH or the command line.

3. How do I install Magento using Composer?

Run the sudo composer create-project command to download Magento. When prompted, provide the necessary credentials in the text box. It simplifies the installation process.

4. What database setup is required for Magento installation?

Use MySQL identified with mysql_native_password for compatibility. Create the database user and grant necessary permissions using MySQL commands.

5. How does AWS pricing work for Magento deployments?

AWS pricing is based on the services used. Examples include the type of EC2 instance, storage, and data transfer.

6. How does Magento leverage applications like Elasticsearch and PHP?

Magento uses Elasticsearch for catalog search and PHP for server-side operations. To optimize performance, combine applications, such as PHP 7.4 and Elasticsearch.

7. How does Magento offer extended functionality via PHP and resources?

Magento delivers eCommerce capabilities that allow you to build a unique online store from scratch. It offers extended functionality via required PHP extensions, which enhance compatibility and performance. For smooth operations, Magento also requires at least 2GB of memory.

CTA

Summary

AWS Magento 2 lets you use a registered domain name and configure it in the AWS Route 53 service for smooth URL redirection. It allows you to:

  • Create powerful, customizable eCommerce solutions.
  • Simplify store management and improve site performance for businesses of all sizes.
  • Optimize your Magento store for reliability and speed.
  • Deliver fast, secure, and flexible solutions for online stores.
  • Ensure an optimized eCommerce platform for your needs.
  • Build a scalable, reliable eCommerce platform.
  • Deploy and optimize your store effectively.

Consider managed Magento hosting to integrate with AWS for scalability and performance.

Dikshya Shaw
Dikshya Shaw
Technical Writer

Dikshya leverages her content marketing and writing proficiency to deliver fresh, insightful content. Her meticulous research ensures industry expertise and emerging trends within the Magento landscape.


Get the fastest Magento Hosting! Get Started