I followed this tutorial in order to deploy my nextjs app to shared hosting on cPanel.
Road map for deploying on cPanel Next App with server-side rendering (not only static) :
Build locally (next build)
Copy into html_folder all your project directory (not only the build folder, and except node_modules of course) :
public_html
my_project
.next
src
server.js
package.json
...
Note: A custom server is needed as cPanel needs a startup file (use the next's default one)
create your node application ("setup node.js app") with options :
Application root : public_html/my_project
Application startup file : server.js
...
"Run NPM install" to create node_modules packages
Finally "Start App"
package.json with the start command :
"scripts": {
"start": "cross-env NODE_ENV=production node server.js"
}
However, visiting my website after going through the entire process gives me this error:
2
Answers
All you really need to do is run
next build && 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.Make sure to copy the .next folder, in the cpanel’s folder, like this:
my_project –> folder in cpanel
_________
| .next | –> this folder
___________
src
server.js
package.json
…
If you can’t see this folder in your project, enable the option to show hidden files.