5

I am trying to deploy next js app on cPanel. I have installed node and npm on it. How can I deploy the next js app on this set up?

I am getting the following error while trying to build the app on cpanel terminal:

Unhandled rejection TypeError: child.send is not a function

  • 1
    To deploy Next.js app, at first you need to execute build script (`npm run build`) which is defined in package.json and `npm run start`. But currently it is not possible to run custom scripts with PussionPassanger which is used in cPanel. It works only by taking `app.js` file as entrypoint. – Lauris Kuznecovs Sep 14 '19 at 16:26
  • any update on this? – Behnam Esmaili Jan 26 '20 at 09:50
  • @LaurisKuznecovs which `app.js` you mean?do i have to select it as `Application startup file` when creating nodejs application? – Behnam Esmaili Jan 26 '20 at 09:51
  • @BehnamEsmaili I don't think it's possible unless you have some kind of elevated access (*like root*) and you definitely going to need SSH access. Check this article [How to Install a Node.js Application](https://documentation.cpanel.net/display/CKB/How+to+Install+a+Node.js+Application). I deploy all node applications using Plesk panel. – Christos Lytras Jan 26 '20 at 11:07

5 Answers5

2

You should run next export to make static html and js files in out you can directly upload it to Cpanel as normal html website you can run npm run export or yarn export by adding

"scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start",
    "export": "next export"
  },

these in package.json

Wolfie
  • 27,562
  • 7
  • 28
  • 55
Rahul Raj
  • 322
  • 3
  • 14
1

You'll need root privileges. If you've got them you can remote into your server via SSH and run the npm commands there. Then it should work. I.e, from console:

ssh user@serverip
cd /path/to/appdirectory
npm run start
nebekerdev
  • 142
  • 9
1

There are some options to deploy NextJS app in CPanel:

  1. You just deploy serverless app (without NodeJS) in CPanel. NextJS has provided a syntax like next export to producing optimized frontend files.
  2. New version of CPanel already has entry point for your nodejs application: Entry point of NodeJS app in CPanel Specify your server file on that field.
Darryl RN
  • 7,432
  • 4
  • 26
  • 46
1

Next.js applications should run fine on a web hosting provider using cPanel, but running the default next.js server tends to exceed process count and memory quotas applied by those types of providers.

However you can make hosting next.js apps work if you build a production version of your app elsewhere and then use a custom server to call your next.js app to handle incoming requests.

I describe the process to deploy a very basic application as a subsite on my website here - https://www.watfordconsulting.com/2021/02/08/deploy-next-js-applications-to-a-cpanel-web-host/

0

All you really need to do is run next export and put the contents of the out folder in the public_html folder or /var/www/html/, /sites-available/, etc, depending on setup.

DJNorris
  • 85
  • 8