Hello Friends!
In today’s Blog we are going to explain how you can install message queue on aws EC2 instance and connect with magento2.
If you are learner and want to learn magento in depth , you can subscribe our youtube channel
So First of all you need to create 1 EC2 instance on AWS
So Login to your aws account and as per above screenshot click on EC2.
Click on Launch Instance
As we are going to install rabittmq on ubuntu 18.04 so select ubuntu as per screenshot.
At initial stage you can choose t3.micro type instance which is a free tier and click on Next.
You will below screen.
Here you don’t need to do anything just click on Next: Add storage.
Now Click on Add Tags
Here you can give tag like Name in key and Rabbitmq server in value or whatever you want to give.
Click Next
Now you need to create security group as per above screenshot.
you need to add 2 type 1 for 5672 and another 15672. where select source for 5672 as anywhere and for 15672 should be your ip so as it should be risky to open for public bcz we will install admin plugin on this ip.
Now Click Review and Launch.
and Finally Click on Launch. You will get popup like below screenshot
If you already have key then select existing key or if not then create new key. and click on launch instance.
You will see your EC2 instance on EC2 dashboard, once it shows running status then open your command and run below command to login to your EC2.
You will see below message, type yes
Now we will install ErLang bcz rabittmq is developed in ErLang.
Run below command
wget -O- https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | sudo apt-key add -
echo "deb https://packages.erlang-solutions.com/ubuntu bionic contrib" | sudo tee /etc/apt/sources.list.d/rabbitmq.list
Now run below commands
sudo apt update sudo apt install erlang
So we have installed ErLang successfully , Now we will install rabbitmq
First of all you need to add rebbitmq repository in ubuntu. So run below command
wget -O- https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc | sudo apt-key add - wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -
echo "deb https://dl.bintray.com/rabbitmq/debian bionic main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list
Now run below command to install RabbitMQ Server
sudo apt update
sudo apt install rabbitmq-server
After installation check if Rabbitmq service is running or not
systemctl status rabbitmq-server.service
Run below command to install rabbitmq plugin
sudo rabbitmq-plugins enable rabbitmq_management
Now open http://publicip:15672 Url so you will see below screen
If you see above screen then congrats. your rabbitmq has been installed successfully.
Now run below command to create user and assign permission
rabbitmqctl add_user admin adminpassword
rabbitmqctl set_user_tags admin administrator
Please keep password strong
After Login in rabbitmq you willl see below screen
Now we will connect magento2 with rabbitMQ, which is installed on EC2 instance. you can connect it with your local instance of magento as well.
just open your app/etc/env.php file and add code as per below highlight.
<?php return [ 'backend' => [ 'frontName' => 'admin_348pwd' ], 'queue' => [ 'amqp' => [ 'host' => '15.185.114.30', 'port' => '5672', 'user' => 'rabit', 'password' => 'admin123', 'virtualhost' => '/', 'ssl' => '' ] ], 'crypt' => [ 'key' => 'c17d9285bd7188b929aeb167c6709690' ], 'db' => [ 'table_prefix' => '', 'connection' => [ 'default' => [ 'host' => 'localhost', 'dbname' => 'phpacademy', 'username' => 'root', 'password' => 'root@123', 'model' => 'mysql4', 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', 'driver_options' => [ 1014 => false ] ] ] ],
Here you can see few parameters we have set
host : if will be public ip of your EC2 instance
port : it will be 5672
user : it will be username of your rabittMQ, Please make sure user has virtual host permission as below
If It dont have any access please click on username, you can see Set permission button, click on it to give access.
Now run php bin/magento setup:upgrade command to sync your consumer and queues to rabittMQ.
If you didn’t created any consumer and queues you will see below queue in rabittMQ
Hope you understand the process for Install RabittMQ on your EC2 instance and connect with your magento2.
In our Next Topic we will understand how you can create new exchange and queues and sync with RabbitMQ and how it works?
Happy Coding and Keep Visiting!.