Setting Up Next.js on AWS EC2 Instance

2021/10/22 min read
bookmark this
Responsive image

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

Create AWS EC2 Instance

Setup Next.js at EC2

After setup the EC2 instance, choose the instance we just created and connect to the instance by using the EC2 instance Connect.

Install Node.js at EC2

SSH into the EC2, then run the following to install the 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 app command create-next-app to setup the default app, after finish the steps mentioned at the command line, run the npm run dev. This will start the server on localhost:3000

npx create-next-app

Verify Next.js at EC2

Since we setup the security group and open the 3000 port, so you can type the EC2's public ip address with port 3000 to load the page.

http://EC2-Public-IPAddress:3000

Conclusion

This blog provide simple steps of how to setup Next.js at AWS EC2 instance, hopefully this can help you get familiar with EC2 with Next.js.