Skip to content

How to deploy a Next.js app from GitHub

Connect the repository and press Deploy. We run your build and start scripts, next build and next start, and every push to GitHub deploys by itself.

Audience
New to running a server
Last checked
Steps
6
Reading time
3 min

To deploy a Next.js app from GitHub, connect its repository in the control panel, press Deploy, then generate a web address. We run your build script and then your start script, which are next build and next start in a new Next.js app. After that, every push to GitHub deploys by itself.

You don't need a Dockerfile or any settings for a standard Next.js app.

On Hostsrc

App hosting is in beta. Order Hobby or Pro and Apps shows in the panel once your payment is confirmed. Final price, no VAT added.

Before you start

  • A Hostsrc account with App hosting turned on. It's in beta, so order Hobby or Pro first.
  • A Next.js app in a GitHub repository, with its package.json in the top folder.

Steps

  1. Step 1: Check the scripts in package.json

    We run the build script, then the start script. A new Next.js app already has both. next start listens on the port in the PORT variable, which we set for you.

    Keep your lockfile in the repository: package-lock.json, pnpm-lock.yaml, yarn.lock or bun.lock. It tells us which package manager to use. To choose the Node.js version, set engines.node in package.json or add a .nvmrc file.

    package.json
    {  "scripts": {    "dev": "next dev",    "build": "next build",    "start": "next start"  },  "engines": {    "node": "22"  }}

    Note

    If your start script sets a port, such as next start -p 3000, remove -p 3000 so the app uses PORT.

  2. Step 2: Connect the repository

    Sign in at control.hostsrc.com (opens in a new tab) with your Hostsrc account. In the header, switch to Apps.

    On Projects, press New, then Connect GitHub, and choose GitHub. GitHub asks which repositories to share: allow your app's repository. Back in Apps, press New again, choose GitHub Repository and pick it.

    The panel makes a project named after the repository, with the app in it as a service. The service opens on Variables.

  3. Step 3: Add the variables

    On Variables, add what your app reads, one New variable each, or paste NAME=value lines in Raw editor.

    Next.js puts NEXT_PUBLIC_ variables into the browser code while it builds. For those, switch Build on next to the variable. A variable with Build on is used only while building, not while the app runs. Leave Build off for server secrets, such as an API key or DATABASE_URL.

    Press Save variables, then Deploy.

    NEXT_PUBLIC_SITE_NAME=My appAPI_SECRET=paste-your-secret-here

    Note

    After you change a NEXT_PUBLIC_ variable, press Deploy again. The browser code only changes with a new build.

  4. Step 4: Watch the build

    Open Deployments. The new deployment shows BUILDING while we install the packages and run next build, and ACTIVE once next start runs. Press View logs to follow the build. We keep the Next.js build cache between builds, so later builds are usually quicker.

  5. Step 5: Give the app a web address

    Open Settings, then Networking. Under Public networking, press Generate Domain. Check that the port is the one in Target port, 8080 unless you changed it, then press Generate. The app gets an address on up.hostsrc.app, such as your-app-production.up.hostsrc.app.

    To use your own domain, press Custom Domain, type the domain and press Add domain. Add the DNS record the panel shows at your domain's provider, then press Check now. The domain shows Live once HTTPS is set up.

  6. Step 6: Push to update the app

    Every push to the repository's branch builds and deploys by itself.

    If a change breaks something, open History on Deployments and open an earlier deployment. Choose Rollback to this in its menu and confirm with Roll back.

Troubleshooting

The page shows an old value of a NEXT_PUBLIC_ variable

NEXT_PUBLIC_ values are fixed when the app builds. Check that Build is on for the variable, save, and press Deploy.

The deploy fails because the app is not ready

The app didn't answer on its port. Check that the start script is next start with no -p, so it uses PORT. If you changed Target port in Settings, the address must use the same port.

My app uses output: 'export'

With output: 'export' in next.config.js, Next.js builds a static site into the out folder, and we serve those files. There is no next start, so server features such as API routes don't run. Remove output: 'export' if you need them.

The build fails

Open the failed deployment and read its build logs. The last lines name the problem. A build that passes on your computer can fail here if a variable it needs at build time doesn't have Build on.