Complete Guide to Spatie Role and Permission in Laravel 11
Read More
Deploying a Next.js application to AWS EC2 provides a scalable and reliable way to manage your web application. By automating the deployment process with GitHub Actions, you can easily push updates to your live application. In this tutorial, we will walk you through the step-by-step process of deploying a Next.js app on an EC2 instance using GitHub Actions.
If you haven’t already created a Next.js application, now is the time to do so. Open your terminal and run the following commands:
You can follow the Next.js official documentation for more details on how to create and configure a Next.js project.
Next, you need to create a repository on GitHub to host your application code.
Here is a sample of the basic commands to push your code:
Here's a step-by-step guide with images.
For more details, refer to the AWS EC2 documentation.
Go to your EC2 dashboard, select your instance, and click Connect.
Use the SSH client or EC2 Instance Connect to access your server.
Change the ownership of the key pair using the following command:
5. Run the SSH command to connect:
To allow traffic to your application:
To automate deployment using GitHub Actions:
.github/workflows
folder.deploy.yml
file with the following content:
To securely provide sensitive information to your workflow:
EC2_SSH_KEY
: Your EC2 instance SSH private key.HOST_DNS
: Public IPv4 address or DNS of your EC2 instance.USERNAME
: The default user is ec2-user
or ubuntu
.TARGET_DIR
: The directory on the EC2 instance where your app should be deployed (e.g., /home/ubuntu/app
).Push your changes to GitHub:
GitHub Actions will automatically run the deployment workflow. You can check the status of your deployment in the Actions tab of your repository.
After deployment, navigate to the public IPv4 address of your EC2 instance in your browser to verify that your Next.js application is live.
Deploying a Next.js application on AWS EC2 using GitHub Actions is a powerful way to manage your web application efficiently. With this setup, you can automate your deployments, reduce manual errors, and ensure a smooth CI/CD pipeline.
For more in-depth tutorials, check out the GitHub Actions documentation and AWS EC2 best practices.
Feel free to share this guide and follow our blog for more DevOps and cloud deployment tips!
Recent posts form our Blog
0 Comments
Like 0