DEV Community

Bobby Orphé HOUESSINON
Bobby Orphé HOUESSINON

Posted on

2 1

Deploying a Next.js Application with Dokku

Introduction

In this article, we will deploy a Next.js application using Dokku (https://dokku.com).

In a previous article, I explained how to deploy a Laravel application with Dokku, also presenting the basics of Dokku. If you are new to this tool, I recommend reading this article before continuing: Deploying a Laravel Application with Dokku, PostgreSQL and Redis.

Assuming you already have Dokku installed on your VPS, let's continue with the configurations.

1. What is Next.js

Next.js is a React framework for building modern web applications. It simplifies development by providing features like server-side rendering (SSR), static site generation (SSG), API routes, and automatic code splitting. It's widely used for building fast, SEO-friendly, and scalable applications.

The deployment process is rather simple.

2. Configuring the Next.js Application

A. Creating the Dokku Application

dokku apps:create myapp
Enter fullscreen mode Exit fullscreen mode

B. Setting Environment Variables

Replace the values in the following command and execute it:

dokku config:set myapp \
    NEXT_PUBLIC_API_URL=myapi.com \
    NGINX_ROOT=.next
Enter fullscreen mode Exit fullscreen mode

C. Assigning a Domain Name

dokku domains:add myapp myapp.com
Enter fullscreen mode Exit fullscreen mode

3. Deployment Configuration

Based on your project structure, Dokku will recognize it as a Node.js application, use the appropriate buildpack, and execute your build script during the deployment phase.

A. Procfile

Create a Procfile to define the processes to be executed:

web: npm run prod
Enter fullscreen mode Exit fullscreen mode

4. Configuring the Local Development Machine

A. Add Remote Repository

git remote add dokku dokku@<SERVER_IP>:myapp
Enter fullscreen mode Exit fullscreen mode

B. Push the Application to Dokku

git push dokku main:main
Enter fullscreen mode Exit fullscreen mode

5. Enabling SSL with Let’s Encrypt (optional)

Secure your application with a free SSL certificate

dokku letsencrypt:set myapp email you@example.com
dokku letsencrypt:enable myapp
Enter fullscreen mode Exit fullscreen mode

Conclusion

With this guide, your Next.js application is successfully deployed using Dokku. Thank you for reading!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay