Step-By-Step Guide to Setting Up Magento 2 on Amazon AWS

Step-By-Step Guide to Setting Up Magento 2 on Amazon AWS

March 23, 2023 / Nirav Shah

Once you have decided to install Magento in Amazon Web Services (AWS), getting started can be daunting. This guide provides step-by-step instructions for installing and migrating Magento to AWS and Magento AWS best practices for setting up an optimized web server. 

First, you must decide which type of web server you want to use with your Magento installed on AWS. In comparison, there are many different types of web servers available like LEMP, LAMP with different types of supportable OS and Database versions. 

Once you have chosen the best web server for Magento, the next step will be to create an Amazon Machine Image (AMI). An AMI is a pre-configured virtual machine that serves as the base of your installation.

You must choose an OS, such as Ubuntu or CentOS, and select other software packages, such as PHP and MySQL. Once you have configured your AMI, you will need to launch it in AWS. At this point, you are ready to install Magento onto the server.


TABLE OF CONTENTS


Step-By-Step Guide to Setting Up Magento 2 on Amazon AWS


What Exactly are AWS Services?


Prerequisites to AWS Hosting for Your Magento Online Store


Setting up a Magento Store on the AWS Ec2


Reasons why AWS Hosting is Perfect for Your Magento Online Store


Key Takeaways


FAQs on Magento AWS Best Practices

What Exactly are AWS Services?

 

Amazon Web Services (AWS) is a precise cloud platform that delivers services to back businesses in diverse fields, like computing, storage, networking, database, analytics, developer & management tools and much more. 

AWS services can be used for building, testing, and deploying applications. AWS allows for faster development time and can help reduce operational costs by providing a trusted platform for businesses. 

You can use Magento AWS QuickStart to deploy a highly accessible Magento architecture on the AWS Cloud, well-automated by AWS CloudFormation. You can even migrate Magento to AWS for better performance and saving in hosting expenses.

 

Prerequisites to AWS Hosting for Your Magento Online Store

 

Magento on AWS hosting is a great way to quickly get your store off the ground and with minimal effort. But before you can start taking advantage of hosting your Magento store on AWS, there are some essential prerequisites to consider. 

 

  • 1.) Understanding the AWS services: Comprehending Amazon Elastic Compute Cloud (EC2), Amazon Simple Storage Service (Amazon S3), Amazon Relational Database Service (RDS), and Amazon Virtual Private Cloud (VPC) will help you create an effective Magento AWS architecture for your store. 

 

  • 2.) Having a valid AWS account: Ensuring you have a valid AWS account and the appropriate access rights is vital, allowing you to set up the necessary services for your Magento store.

 

  • 3.) Install a compatible operating system: Magento versions 2 and above back Linux, Windows Server 2008R2 or higher, Mac OS X 10.7+ and Android. Each operating system has its installation requirements, so it is essential to ensure the instance you choose meets the requirements.

 

  • 4.) Install an appropriate database and web server: Magento supports MySQL and MariaDB for databases and Apache, Litespeed or Nginx for web servers. Installing the necessary server modules, such as PHP and mod_rewrite, is also essential. 

 

Finally, you must ensure you have the necessary software and licenses installed. Magento is a paid platform, so it is crucial to purchase the license to use the platform. You will need to ensure you have a compatible version of Magento that your OS supports. 

 

Setting up a Magento Store on the AWS Ec2 

 

Here are the fundamental steps for setting up a Magento store on AWS Ec2.

Setting up an EC2 instance with Ubuntu 22.04 with Nginx, MySQL 8 or MariaDB 10.4 and PHP-8.1(it is the required version for magento 2.4.4) with all the necessary software components to run Magento.

 

Step 1:

We will gain ssh access into the Instance and start configuring the Instance for Installation. We are going to ssh into the Instance through the command-line.

$ ssh -i “private-key.pem” ubuntu@(ip-address)

And we are able to connect to the Instance.

Now, the first thing we need to do is update the packages installed on the Instance as well as install some basic packages as per the requirements. First, we will update and clean the system by entering :-

$ sudo apt update && sudo apt upgrade -y

 

 Step 2:

Now, we will set up a LEMP environment by manually installing all the required components 1 by 1 instead of installing the LEMP stack packages as a whole. We will do this to be able to update the latest stable versions of different packages instead of feeling limited by the versions provided by LEMP stack packages. This will also result in it becoming easier to update your LEMP environment in the future instead of waiting for the LEMP stack package maintainers to compile and provide the updated versions.

We will start by installing Nginx web server ,a high-performance web server, on your Linux server. Configure Nginx to serve as the reverse proxy for Magento, handling incoming HTTP requests and forwarding them to PHP for processing:-

$ sudo apt-get install nginx -y

Open TCP port 80 and 443 in the firewall.

$ sudo ufw allow 80/tcp

$ sudo ufw allow 443/tcp

Now, nginx has been installed.

Now, we will install php and its extensions and configure PHP settings according to Magento’s requirements, such as memory limit, max execution time, etc.:-

Magento 2.4.4 is fully compatible with PHP 8.1. To install PHP 8.1 and the required PHP extensions, run the following command:

$ sudo apt install -y php-imagick php8.1-fpm php8.1-mbstring php8.1-soap php8.1-bcmath php8.1-xml php8.1-mysql php8.1-common php8.1-gd php8.1-cli php8.1-curl php8.1-zip php8.1-intl

 

Step 3:

Now, php has been installed with its dependencies.

Now, we will install and set up a mysql server, a popular relational database management system on your Linux server. Create a new MySQL database and user for Magento, and grant necessary permissions to the user.

Magento currently supports: MySQL-8, MariaDB-10.4. MariaDB 10.5 or higher is not supported. Ubuntu 22.04 repository includes MariaDB 10.6, so we will choose MySQL instead of MariaDB.

Run the following command to install MySQL 8.0 from the default Ubuntu repository

$ sudo apt install mysql-server-8.0 -y

Once it’s installed, MySQL server will be automatically started, as can be seen with:

$ sudo systemctl status mysql

Log into MySQL console as root with the following command.

$ sudo mysql -u root -p

Once you are logged in, create a database using the following command. I named it magento, but you can use whatever name you like such as your site name. (Don’t leave out the semicolon.)

CREATE DATABASE magento;

Then enter the command below to create a database user for Magento. Replace password with your preferred password.

CREATE USER ‘magentouser‘@’localhost’ IDENTIFIED BY ‘password‘;

Next, grant permissions to this user.

GRANT ALL PRIVILEGES ON magento.* to ‘magentouser‘@’localhost’;

Flush the privileges table for the changes to take effect and then get out of MySQL console.

FLUSH PRIVILEGES;

At this point, your database system is now set up.

We need to flush the privileges so that the current instance of MySQL knows about the recent changes we’ve made.

At this point, you are ready to install Magento onto the server.

 

Step 4:

Download the latest version of Magento from the official Magento website. Extract the files to your desired location on the server. 

Magento uses Composer to manage its components and dependencies. To install Composer on your server, run the following command:

$ sudo apt install -y composer

Create a web root directory for Magento.

$ sudo mkdir -p /var/www/magento/

Make sure the www-data user can write to this directory.

$ sudo chown -R www-data:www-data /var/www/ 

Change to the /var/www/ directory.

$ cd /var/www/

Now, it’s time to download and install Magento using Composer. We’ll download the latest version of Magento, i.e., 2.4.4.Create the Magento project.

Note: The repo.magento.com URL requires user authentication. Go to https://marketplace.magento.com/ to create an account, then go to this URL (https://marketplace.magento.com/customer/accessKeys/) to create an access key for Magento 2. 

$ sudo -u www-data composer create-project –repository-url=https://repo.magento.com/ magento/project-community-edition magento

Running the above command, you will be asked for your username and password.

Username: Your Public Key

Password: Your Private Key

Next, run the following commands to set file permissions.

$ cd /var/www/magento/

$ sudo find . -type f -exec chmod 644 {} \;

$ sudo find . -type d -exec chmod 755 {} \;

$ sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod  

g+ws {} +

 $ sudo chown -R www-data:www-data .

$ sudo chmod u+x bin/magento         

$ sudo  chmod -R 777 var/ pub/ generated/

$ sudo chmod -R 644 ./app/etc/*.xml

 

Step :5

Configure Nginx for Magento

Configure Nginx to serve Magento using virtual hosts, server blocks, or location blocks. Set up appropriate Nginx directives for handling PHP requests, URL rewriting, and SSL if needed.

Magento ships with a sample Nginx config file in /var/www/magento/ directory. Move it to the /etc/nginx/conf.d/ directory.

$ sudo mv /var/www/magento/nginx.conf.sample /etc/nginx/conf.d/magento.sample

We create a new virtual host file for Magento in the /etc/nginx/conf.d/ directory. The file name must end with .conf.

$ sudo nano /etc/nginx/conf.d/magento.conf

Then test Nginx configurations.

$ sudo nginx -t

If the test is successful, reload Nginx.

$ sudo systemctl reload nginx

$ cd /var/www/magento/

 

Step :6

Secure your Magento installation

Follow Magento’s security best practices, such as changing default admin URLs, setting strong passwords, enabling SSL, and applying necessary patches and updates to keep your Magento installation secure.

Run the following command to install Magento.

$ sudo -u www-data bin/magento setup:install –base-url=http://magento.eternalsoft.in –use-secure=1 –base-url-secure=https://magento.eternalsoft.in –use-secure-admin=1 –db-host=localhost –db-name=magento –db-user=magento –db-password=456782sd –admin-firstname=super –admin-lastname=admin –admin-email=contact@eternalsoftsolutions.com –admin-user=admin –admin-password=67890rtf54 –language=en_US –currency=USD –timezone=America/Chicago –use-rewrites=1 –elasticsearch-host=http://127.0.0.1 –elasticsearch-port=9200 –elasticsearch-enable-auth=0

As you can see, Magento is installed successfully.

 

Step :7

Test your Magento installation to ensure everything is working correctly. Optimize your LEMP server configuration and performance settings for best performance, such as enabling caching, setting up opcode caching, and optimizing MySQL settings.

 

Reasons why AWS Hosting is Perfect for Your Magento Online Store 

 

AWS hosting is the perfect fit for your Magento online store. With its easy-to-use tools, AWS makes it possible to install and manage Magento quickly and easily. Plus, AWS offers a range of features that make it the seamless solution for your online store.

  • A.) Installing Magento: With the AWS hosting platform, you can easily install Magento. You do not need to worry about downloading and configuring the software, as you can get a ready-to-use Magento instance in minutes. This makes it easy to get your store up and running quickly.
  • B.) Store Set Up: Once your store is set up, you will benefit from Amazon’s reliable hosting service. AWS offers a wide range of products that support Magento stores, including top-of-the-line security and scalability. This means you will not have to worry about your store slowing down or experiencing outages due to high traffic.
  • C.) AWS Hosting: You can access various resources and tools that can help you make the most of your Magento store with AWS hosting. The hosting tools can help you optimize performance, customize functionality, and improve the user experience for your customers.
  • D.) Scaling Flexibility: You can adjust your plan to fit your budget and scale up or down as needed. This makes it picture-perfect for companies of all categories and sizes.

There are both pros and cons of AWS hosting. However, regarding the benefits, AWS hosting is cost-effective and allows better scalability.

 

Key Takeaways

 

In conclusion, this guide has provided a comprehensive overview of the necessary steps required to install Magento in AWS. With an understanding of AWS services, why AWS hosting is perfect, and a process to set up your Magento store on the AWS cloud, online store owners can take their business to the next level by using AWS cloud capabilities. 

The possibilities for growth and success when using AWS services are endless, so there is no better time than now to make that leap. Whether you are looking for scalability, cost-effectiveness, or a reliable platform to do business – Amazon Web Services offers them all!

 

FAQs on Magento AWS Best Practices

 

1.Can I install Magento without Elasticsearch?

Yes, you can install Magento without Elasticsearch. The benefit of Elasticsearch is that it improves the search speed and accuracy for the user. It provides sophisticated search capabilities like full-text search, advanced analytics, and sorting options.

However, you do not need to use Elasticsearch to have a working Magento system. Instead, you can use other solutions such as MySQL’s built-in Full-Text Search or Apache Solr.

2.Is Magento a CMS or MVC?

Magento is an open-source eCommerce platform that combines Content Management System (CMS) and Model View Controller (MVC) architecture. 

The CMS portion of Magento allows users to access content, manage it and display it on their online stores. The MVC architecture enables developers to separate business logic from presentation layers making development faster by allowing the two components to be managed independently.

3.What is the best hosting for Magento?

The best hosting for Magento offers a robust and reliable platform upon which to build your eCommerce store. It should provide resources like bandwidth, storage space, RAM, and CPU power, to ensure your store runs smoothly without slowdowns or outages. It should offer customer support if you need help troubleshooting any issues you may encounter while operating your store.

4.Does Magento use AWS?

Yes, Magento does utilize the Amazon Web Services (AWS) platform. AWS offers an enterprise-level service that provides secure and scalable cloud computing services to businesses of all sizes. Magento can run on AWS in several ways.

sri

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let Us Talk About Your AWS Development Requirements

    Have queries about your AWS project ideas and concepts? Please drop in your project details to discuss with our AWS experts, professionals and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project