How to deploy a nextjs application on cpanel?
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 foldergo 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?
I uploaded out
(which gets generated doing npm run build && npm run export
) folder to public_html
and created .htaccess
file like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-L
RewriteRule . /index.html [L]
</IfModule>
It worked for me 😁
Problem: When I refresh the page on some different route let's say
/about
, it brings theindex.js
page contents but URL doesn't change to/
- Your
.next
doesn't have index.html file. - Seems like you have server side (mostly using nodejs), but unfortunately you couldn't run that server side from cpanel.
- As I know, you should use
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.