> ## Documentation Index
> Fetch the complete documentation index at: https://sensei.aisbirnusantara.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Deploy Next.js on DirectAdmin

> Comprehensive guide to deploying a Next.js production app using a custom server.js on DirectAdmin

<iframe width="100%" height="400" src="https://www.youtube.com/embed/r7N87i_Hw0k" title="Tutorial Deploy Next.js on DirectAdmin" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen style={{ width: '100%', borderRadius: '0.5rem', marginBottom: '1.5rem' }} />

This guide explains how to deploy a **Next.js** application (SSR / Production Build) on Aisbir Cloud DirectAdmin hosting using a custom `server.js` runner.

***

### 1. Create `server.js` in Your Project Root

In your local Next.js project root directory, create a file named **`server.js`** and add the following code:

```javascript server.js theme={null}
/* eslint-disable @typescript-eslint/no-require-imports */
const { createServer } = require("http");
const next = require("next");
const { parse } = require("url");

const port = process.env.PORT || 3000;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();

app.prepare().then(() => {
    createServer((req, res) => {
        const parsedUrl = parse(req.url, true);
        handle(req, res, parsedUrl);
    }).listen(port, (err) => {
        if (err) throw err;
        console.log(`Serve At http://localhost:${port}`);
    });
});
```

***

### 2. Build Your Next.js Application Locally

Run the production build command in your terminal:

```bash theme={null}
npm run build
```

Verify that the **`.next`** build folder has been successfully generated.

***

### 3. Compress Project Files into a ZIP Archive

Select and compress the following files into a single `.zip` archive (e.g. `nextjs.zip`):

* `.next` folder
* `public` folder (if containing static assets/images)
* `server.js` file
* `package.json` & `package-lock.json`
* `.env` file (if you have environment variables)

<Warning>
  **DO NOT include the `node_modules` folder!** Dependencies will be installed cleanly on the server.
</Warning>

***

### 4. Upload and Extract in DirectAdmin File Manager

1. Open **File Manager** in your DirectAdmin panel.
2. Navigate to `domains` -> `[yourdomain]` -> **`public_html`**.
3. Upload `nextjs.zip` into `public_html`.
4. Right-click the `.zip` file and select **Extract** to unpack everything into `public_html`.

***

### 5. Setup Node.js App in DirectAdmin

1. Open the **Setup Node.js App** tool in DirectAdmin.
2. Click **Create Application**:
   * **Node.js Version**: Select the appropriate Node version (e.g. Node 18 or Node 20).
   * **Application Mode**: Set to `Production`.
   * **Application Root**: Enter your website root path (e.g. `domains/yourdomain.com/public_html`).
   * **Application URL**: Select your domain name.
   * **Application Startup File**: Enter **`server.js`**.
3. Click **Create**.
4. Click **Run NPM Install** on the Node.js configuration page to install all dependencies.
5. Click **Restart** / **Start Application**.

***

## Done 🎉

Your Next.js application is now running seamlessly on DirectAdmin!
