I followed these steps to deploy my nextjs on cPanel.
-
go to package.json and add this line:
"homepage": "http://afsanefadaei.ir"
-
run
next build
to have.next
folder as my build folder -
go to
cpanel >> file manager >> public_html
folder and upload the contetn of.next
folder to this directory -
add or edit this file:
.htaccess
to:
but when I go to the website I face this:
Do you know what is wrong with this?
5
Answers
.next
doesn’t have index.html file.next export
instead ofnext build
if you tend to have frontend side only.But the most important thing is number 1, make sure you have
index.html
inside your.next
folder.I uploaded
out
(which gets generated doingnpm run build && npm run export
) folder topublic_html
and created.htaccess
file likeIt worked for me 😁
Deploy it as a NodeJS application.
I could host the application with one of the above answers, but when I refresh the page the application will crash or go to initial route.
This is how I solved this problem (solution taken from next.js official site).
npm run build
app.js
in the root folder and copy the following codeCreate a Node.js Application on cPanel and add Application Startup File name
And start the application. You are done !
For further information check out the official docs of Next.js Custom Server
Here is a complete
.htaccess
for implementing a Node.js application with an Apache redirect. This works very well on cPanel if you have your NextJS app deployed with thenext start
server (listening on a specific port).