How to Deploy a Next.js App in cPanel
Can I host Next.js on cPanel hosting? Yes. A static Next.js site runs on every HosterPK plan. A Next.js app with server rendering or API routes runs as a Node.js app through "Setup Node.js App" in cPanel; we recommend Hosting Plan II or above. You do not need SSH.
Which kind is your app?
- Static export (
output: 'export'innext.config.js): runnpm run buildon your computer and upload the contents of theoutfolder topublic_html. Nothing else is needed. - Server rendering or API routes: follow the steps below.
Steps for a server-rendered app
- Build on your computer. Run
npm run build. The build does not run on shared hosting, so do not skip this step. - Add a start-up file named
server.jsto the top folder of the project. cPanel starts your app itself, sonext startis not used. This is the file tested on our servers:const { createServer } = require('http'); const next = require('next'); const app = next({ dev: false, dir: __dirname }); const handle = app.getRequestHandler(); app.prepare().then(() => { createServer((req, res) => handle(req, res)).listen(process.env.PORT || 3000); }); - Upload the project to a folder outside
public_html, for examplemyapp. Include the.nextfolder. Do not upload thenode_modulesfolder. - Create the app. In cPanel open "Setup Node.js App" and click CREATE APPLICATION, then fill in the form:
- Node.js version: choose 24.
- Application mode: change "Development" to "Production".
- Application root: the folder from step 3, for example
myapp. - Application URL: choose your domain. Leave the box beside it empty to run the app on the whole domain.
- Application startup file:
server.js - Environment variables: click ADD VARIABLE for each value your app needs, such as a database password.
- Install the packages. Under "Detected configuration files" click Run NPM Install. For a Next.js app this takes about 10 minutes; wait for it to finish.
- Click RESTART and open your address.
How much space it needs
A minimal Next.js app installs about 350 MB of packages. On real apps hosted with us the figure is 500 to 900 MB. That is why we recommend Hosting Plan II (2,000 MB) or above.
Changing the Node.js version later
- Open the app in "Setup Node.js App", choose the new version under Node.js version and click SAVE.
- cPanel reinstalls your packages for the new version by itself. In our test this took about 5 minutes, and the site answered slowly meanwhile.
- Click RESTART. Until you do, the app keeps running on the old version.
The old version's packages stay on your account, so each version you have used takes its own space: about 350 MB each for a small Next.js app.
If the build fails on the server
That is expected. Running the Next.js build on shared hosting, including through the Run JS script button, stops with an error such as "Out of memory". Build on your computer and upload the project with its .next folder, as in steps 1 and 3.
Still stuck? Open a support ticket or start a live chat, and we will create the app, install the packages and start it for you. See the plans on our Node.js hosting page.