How to Deploy Next.js on cPanel/WHM with Phusion Passenger — A Practical Guide for Small Businesses

How to Deploy Next.js on cPanel/WHM with Phusion Passenger — A Practical Guide for Small Businesses

Introduction

If your business wants a fast, modern website but you’re hosting on cPanel, you don’t have to move everything to a cloud platform. This guide explains in simple terms how to run a production Next.js site on cPanel/WHM using Phusion Passenger. Read on to learn the practical steps, trade-offs, and when a static site might be a better fit.

Why this approach matters

Next.js can either serve pages server-side (SSR) or export a static site. Running SSR gives you dynamic content and better SEO for certain pages, but it needs Node.js running on the server. Phusion Passenger is an easy way to run Node apps alongside Apache or nginx on cPanel, letting your Next.js app respond to real HTTP requests without a separate server process you must manage.

Quick checklist before you start

Make sure you have: - A cPanel account with SSH access (highly recommended). - Confirmation that Passenger or a “Node.js App” feature is available, or WHM access to install Passenger. - A compatible Node version (check Next.js docs for the required LTS). - Your Next.js project ready to build (package.json, next.config.js, and source files).

Prepare your Next.js app

Keep things simple and production-ready: - Add scripts in package.json for build and start (for example: build → next build, start → next start -p $PORT). - Use a minimal startup file (server.js) if you prefer Passenger to run node server.js. The server should listen on process.env.PORT. - Decide if you can use a static export (next export). If you don’t need SSR, exporting to static HTML is the easiest, lowest-cost option.

Build on the server when possible so native modules match the host Node version. Run npm ci and npm run build in your app folder.

Enable Passenger in WHM (if you manage the server)

If you’re the server admin, install Passenger via EasyApache in WHM for the cleanest integration. Steps overview: 1. WHM → EasyApache 4 → Customize → enable Passenger module. 2. Provision changes and restart Apache. 3. Optionally set PassengerNodejs to pin a Node binary used for apps.

If you’re on shared hosting, ask support whether Passenger is enabled or if cPanel’s “Setup Node.js App” is available.

Deploying under cPanel

Two common ways to deploy: 1. Use cPanel’s Node.js App manager (if present): it handles Node version, environment variables, and startup commands. 2. Manual Passenger setup: upload your app to your home directory, install dependencies, build, and create a vhost include or rely on Passenger’s automatic spawning when the domain points to your app folder.

General steps: - Upload or git clone your project into ~/your-app. - SSH: npm ci (or npm install) and npm run build. - In cPanel App manager, set the application root and startup file (server.js or npm start). - Start the app and check logs if needed.

Domains, environment variables and SSL

Passenger runs behind Apache, so SSL is controlled at the webserver level. Use cPanel/WHM AutoSSL to get certificates. For environment values: - Use the Node.js App UI in cPanel if available. - Or set SetEnv in a vhost include for persistent vars. Always keep secrets out of source control and use cPanel’s UI to store production variables securely where possible.

Quick troubleshooting tips

If you see 502/503 errors or the app won’t start, check: - Did you run npm run build? Next needs a production build. - Is your startup script listening on process.env.PORT or using next start -p $PORT? - Are node_modules present and compatible with the Node version? Re-run npm ci on the server. - File permissions: files should be owned by the cPanel user (chown -R username:username). - Check Apache/error logs and Passenger output for concrete errors.

When to pick static export vs SSR

Use static export when: - Your site is mostly marketing pages and rarely needs dynamic server rendering. - You want the simplest, most stable hosting experience on shared plans.

Choose SSR when: - You rely on getServerSideProps, server-side APIs, or personalized content that must be rendered on-demand.

Want help getting this done?

If you’d rather focus on leads and conversions while someone else handles hosting and performance, we can help. Visit our homepage at https://prateeksha.com?utm_source=blogger to learn about services, or browse more tutorials on our blog at https://prateeksha.com/blog?utm_source=blogger. This post is part of a deeper guide — see the full step-by-step article here: https://prateeksha.com/blog/deploy-nextjs-cpanel-phusion-passenger?utm_source=blogger

Conclusion — next steps

Decide first whether you need SSR or a static site. If SSR is required, confirm Passenger and a compatible Node version with your host, prepare a clean startup script that honors process.env.PORT, and build on the server to avoid module mismatches. If this feels like too much setup, reach out and we’ll help you deploy a fast, reliable Next.js site that converts visitors into customers.

Comments

Popular posts from this blog

From Valet to Herd: Transitioning Your Laravel Development Environment

Next.js - Built-In API Routes Revolutionizing Full-Stack Development

Is Gatsby.js Dead? A Comprehensive Look into the State of Gatsby in 2024