Setting Up Next.js on AWS EC2 Instance

2021/10/022 min read
bookmark this
Responsive image

Table of Contents

  1. Introduction
  2. Create AWS EC2 Instance
  3. Setup Next.js at EC2
  4. Verify Next.js at EC2
  5. Conclusion

Introduction

Next.js is a React-based web application framework built on top of Node.js. AWS EC2 is Amazon's cloud computing service which hosts VMs in the cloud. In this tutorial, we will manually create an EC2 instance, then SSH into the instance and install and set up Next.js.

Create AWS EC2 Instance

Setup Next.js at EC2

After setting up the EC2 instance, choose the instance we just created and connect to it by using EC2 Instance Connect.

Install Node.js at EC2

SSH into the EC2, then run the following to install Node.js.

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

Create Next App

We'll use the Next.js command create-next-app to set up the default app. After finishing the steps mentioned in the command line, run npm run dev. This will start the server on localhost:3000.

npx create-next-app

Verify Next.js at EC2

Since we set up the security group and opened port 3000, you can type the EC2's public IP address with port 3000 to load the page.

http://EC2-Public-IPAddress:3000

Conclusion

This blog provides simple steps for how to set up Next.js on an AWS EC2 instance. Hopefully this can help you get familiar with EC2 and Next.js.