Installing Magento 2 on AWS with Terraform

In this blog we will see Installing magento 2 on AWS with Terraform and at the end of this blog you will be able to deploy magento 2 on AWS using terraform.

Prerequisites

  • Ubuntu 18.04
  • Account on AWS
  • Magento 2 tar file must be downloaded on system

In this Blog we will see

  • What AWS resources are build
  • How we create Access Key and Secret Key in AWS
  • How we create Key Pair in AWS
  • What’s inside the zip file
  • Download terraform files to build AWS resources
  • Initialize the folder
  • Plan for the magento 2 setup
  • Apply for the magento 2 setup
  • Test magento 2 site
  • Conclusion

What AWS resources are build

By the help of this terraform files the AWS resources which are build.

  • EC2 Instance with
    • t2.micro instance type
    • Attached elastic IP
  • EBS Volume with
    • 30 GB Storage
    • Volume type is General Purpose 2.
  • RDS DB Instance with
    • 20 GB storage
    • Mysql version 5.7.23
    • db.t2.micro instance class
    • Parameter Group attached with DB
    • Enabled backup and maintenance mode
  • Security Group with
    • EC2 instance security group with inbound ports 22, 80, 443.
    • RDS DB instance security group with inbound ports 3306.

How we create Access Key and Secret Key in AWS

To create access key and secret key follow the procedure:

  • Login to your AWS account.
  • In the service section choose for “IAM” service,
  • In “IAM” service in the left side slider you will find “Users”.
  • Click on “Users” it will get you on users page.
  • At the top left of users page you will find “Add user”.
  • Click on “Add user” then enter the “username” and select the access type as “Programmatic access”.
  • When we choose “Programmatic access” at the end of this process you get Access key and Secret Key.
  • Now press “next” to add permissions for the user.
  • Then in this part choose “Attach existing policies directly” by searching and selecting for “AmazonEC2FullAccess” and “AmazonRDSFullAccess”. After this press “next”.
  • Want to use tags for user then add key and value and then press “next’.
  • Now in this part you can review all your configuration. And then click on “Create User”.
  • After creating user successfully you will find button to “Download .csv” which contains Access key and Secret key.

How we create Key Pair in AWS

If you don’t have any “Key Pair” or wants to create new one then follow this steps.

  • Open AWS account.
  • In “Compute” services go for “EC2” service.
  • Then at left side slider of EC2 service you will find “Network and Security”.
  • In “Network and Security” click on “Key Pair”.
  • In “Key Pair” at the top right corner you will find “Create Key Pair” click on it.
  • Enter the name of Key Pair, choose file format “pem” and then click on “Create”.
  • After creating the Key Pair the .pem extension file will automatically downloaded in your system.

What’s inside the zip file

In this zip file of magento with terraform you will get.

  • ec2.tf – By this we build EC2 instance along with elastic ip address.
  • mysql.tf – Which is use to create mysql user, Database, and Grant permissions to user.
  • provider.tf – Is use for terraform plugins which are used in this terraform script.
  • random.tf – Is use to generate password for RDS admin user.
  • rds.tf – By this we build RDS DB instance along with parameter group.
  • security-group.tf – Which is use to build security groups for EC2 instance and RDS DB instance.
  • variables.tf – Is use to take the values for all variables use under this script.
  • magento-2.sh – Which contains all the commands to install magento 2 in EC2 instance.

Download terraform files to build AWS resources

Before we start if you didn’t install terraform in your ubuntu 18.04 then follow link.

Now to download the zip file of terraform for magento 2 then click on link.

By this command the zip file is downloaded in your ubuntu machine.

Now “unzip” the file by command.

Enter the .pem file path in “ec2.tf” file to connect with EC2 instance.

In the Connection part of instance you will find “private_key”, enter the Key Pair path along with key at the location.

After that save the file by “ctrl+x” to exit, “y” to save and press “enter”.

Now edit “variables.tf” files to use the terraform script.

And enter the values of variables according to your AWS account. After that save the file by “ctrl+x” to exit, “y” to save and press “enter”.

Initialize the folder

In this step go to the location where all the terraform “.tf” files are located.

With the help of this initialize command terraform will download the required plugins like AWS, mysql, etc.

After completion of this command you will find hidden directory with name .terraform.

Plan for the magento 2 setup

In this step after initialize the folder, with the help of this command you will check the plan of resources which are going to create after apply command.

By this command all the resources which are going to create are shown.

Apply for the magento 2 setup

By this step we will get the execution plan to confirm the installation.

In execution plan it will show all the details of resources which will be created after installation.

After using this command it will show the execution plan and ask us to confirm that plan for further installation.

Test magento 2 site

After all this process go to your browser and open the magento 2 site with the help of “IP address”.

http://<ip-address>

It will show the Installation page of magento 2.

Conclusion

With this we can easily setup LAMP server and configure ec2 and RDS in our AWS account by some commands. After completion of this we can run our magento 2 site in the browser.

In case of any help or query, please contact us or raise a ticket.

Category(s) aws cloud
. . .

Comment

Add Your Comment

Be the first to comment.

css.php