How can I deploy Next js app on cpanel hosting
Asked Answered
D

5

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

Disinfect answered 3/6, 2019 at 9:48 Comment(4)
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.Allottee
any update on this?Saltine
@LaurisKuznecovs which app.js you mean?do i have to select it as Application startup file when creating nodejs application?Saltine
@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. I deploy all node applications using Plesk panel.Periotic
T
3

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

Twinge answered 2/2, 2020 at 3:52 Comment(1)
downside with this approach is server databinding not working.Saltine
E
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
Excitor answered 31/1, 2020 at 22:37 Comment(2)
in shared hosting root privilage is not available.Saltine
See "you'll need root privileges." I don't believe it's possible to do this at all without them, but I could be mistaken.Excitor
D
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.
Delisle answered 2/2, 2020 at 3:36 Comment(2)
What file is the entry point for a nextjs application?Mulatto
you can define your server file if you use NextJS with server. otherwise just point to your index for serverless NextJS appDelisle
P
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/

Peraea answered 11/2, 2021 at 9:26 Comment(0)
O
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.

Objectionable answered 13/6, 2021 at 22:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.