DEV Community 👩‍💻👨‍💻


Posted on

Manually Deploy Next.js on AWS EC2 with Shell Script

Do you want to know how to manually deploy an application without all advanced tools, just use shell script on Linux? Before we have CI/CD, Github Actions, AWS Codedeploy, etc. developers need to manually execute scripts to deploy, and I will show you brief steps to complete it.

Let me show you with a Next.js application, and I will deploy it on AWS EC2.

Once you connect to your server, execute the following code:

# Optional: clone code if you don't have app code on your destination server, example: git clone
$ git clone <your app's' repo url>

# example: cd /home/ec2-user/next.js
$ cd <filepath of the directory you just cloned>

# install dependencies
$ npm install 

# build 
$ npm run build

# stop running process, example: ps -ef | grep ec2-user/next.js | grep -v grep |awk '{print $2}'| xargs kill -9
$ ps -ef | grep <app directory> | grep -v grep | awk '{print $2}'| xargs kill -9

# start app as a daemon process 
$ (npm run start > /dev/null 2>&1 &)

Enter fullscreen mode Exit fullscreen mode

You can view details at here

Top comments (0)

👋 Have You Posted on DEV Yet?

Head over to our Welcome Thread and tell us a bit about yourself!