So I first built a NextJS app on my local PC, I then uploaded the project to cPanel. I created a NodeJS selector for the project and configured the settings as per the cPanel instructions and all seemed good. When I call npm start on the command line, the project runs perfectly and in the browser.
The issue that I am struggling with is configuring an appropriate startup script to run the NextJS server, without creating a custom server for it (and more specifically, without losing the static optimization capabilities).
I have tried creating an app.js file for the startup script which attempts to import this next-start server and call it. (Gave the error 'nextStart is not a function'). The suggestion for this can be found here
I have also tried to run exec('next-start') in the app.js file. This file worked if I called it in command line, however it did not work when added to the cPanel NodeJS selector. The code is as follows:
const {exec} = require('child_process');
exec('npm start');
I can't use pm2 because it is a shared hosting account and therefore I don't have root access to be able to configure pm2 to restart the process on server restart (incase of crashes etc).
Does anyone have any valid methods of deploying a NextJS server to a cPanel shared hosting account, without compromising NextJS automatic static optimization?