Deploying a MERN Website on Amazon EC2

In this blog post, we'll walk through the steps to deploy a MERN (MongoDB, Express, React, Node.js) website on an Amazon EC2 instance. EC2 (Elastic Compute Cloud) is a cloud computing service provided by Amazon Web Services (AWS) that allows you to run virtual servers, known as instances, in the cloud.

Prerequisites

Before we begin, make sure you have the following:

  1. An AWS account
  2. A MERN application that you want to deploy
  3. Knowledge of basic command-line operations

Step 1: Create an EC2 Instance

  1. Log in to the AWS Management Console and navigate to the EC2 service.
  2. Click on the "Launch Instance" button to create a new EC2 instance.
  3. Choose an Amazon Machine Image (AMI) that suits your needs. For this example, I'll use the Ubuntu AMI.
  4. Select an instance type. The instance type determines the compute, memory, and storage resources of your virtual server. Choose an instance type that matches the requirements of your MERN application.
  5. Configure the instance details as needed, such as the number of instances, network settings, and storage options.
  6. Allow SSH or HTTP traffic to connect the instance with the internet.
  7. Review and launch the instance.

Step 2: Connect to your EC2 Instance

  1. Once the instance is running, you can connect to it using SSH or EC2 instance connect.
  2. You should now be connected to your EC2 instance.
  3. Run below command to super user who can install and run any command

sudo -i        

Step 3: Set up the MERN Environment

  1. Update the package manager and install the install the necessary dependencies:

sudo apt update -y        

2. Install Node.js and npm:

curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
sudo yum install -y nodejs        

3. Install MongoDB:

sudo tee /etc/yum.repos.d/mongodb-org-4.4.repo << EOF
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
EOF

sudo yum install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod        

Step 4: Deploy your MERN Application

  1. Clone your MERN application repository to the EC2 instance: Give the name of your git repository where your code is written and StudentErp is my repository name you will write your repository name.

git clone <your-repo-url>
cd StudenErp        

3. Install the required dependencies for the server and client:

update
cd client 
apt install nodejs
apt install npm
npm i
npm start        

Your MERN website should now be accessible at your EC2 instance's public DNS address or IP address.

Conclusion

Deploying a MERN website on Amazon EC2 involves several steps, including creating an EC2 instance, setting up the development environment By following the steps outlined in this blog post, you should be able to successfully deploy your MERN application on the cloud and make it accessible to your users.

Remember, the specific configuration and setup may vary depending on the requirements of your application and your familiarity with AWS and the MERN stack. It's always a good idea to thoroughly test your deployment before going live and to keep your application and infrastructure updated with the latest security patches and best practices.

I would like to express my sincere gratitude to my trainer, who has provided me with the knowledge and guidance to create this comprehensive guide on deploying a MERN website on Amazon EC2. Their expertise and dedication have been instrumental in my learning process, and I am grateful for the opportunity to share this information with you. Thank you Mr. Ashutosh Singhal sir REGex Software Services #aws #learn #grow #happy deploying

要查看或添加评论,请登录

Muskan Sadarangani的更多文章

社区洞察

其他会员也浏览了