poor content

not useful

useful

very useful

excellent

Rate

Deploy static nextjs to cpanel

February 20, 2022

Alireza Ataei

By: Alireza Ataei

How to deploy static Nextjs app Cpanel

Reading time: min

    Content List

After setting up your application on localhost, it time to deploy your next js to your cPanel, but it's not without challenge

The first step would be to prepare your next.js web pages for to deploy as html files beside the other assets required, if you haven’t, check this link Setup next.js for static exporting

 

Then check your package.json build script to

“build”: “next build && next export”

 

The run the npm run build in your terminal

If you get an Error like this:

Image Optimization using Next.js’ default loader is not compatible with `next export`.

Then create a next.config.js if you haven’t already, and add the following script to module.exports

  images: {
    loader: ‘akamai’,
    path: ‘/’,
  }

rexfont config nextjs

 

If the command is successful, then you should see a folder generated named out

And there should be static html files generated, such as index.html, like this:

rexfont out nextjs folder

 

now move the content of the folder or the whole folder to the directory of your cPanel as you wish such as the public_html

The next important step is to setup the .htaccess in your directory properly, so if you have copied the content of the out folder to the public_html for example, you can setup the .htaccess as the following query

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
</IfModule>

Was this page helpful?

What was the most helpful point of this page for you?

Thanks for your cooperation!

poor content

not useful

useful

very useful

excellent

Comments3

3 responses to “How to deploy static Nextjs app Cpanel”

    • Hi there, happy to help.
      Would you be able to provide more information on the problem, if you may? at what point did you get the error? while exporting? or after deployment? or in the middle of the dev process?
      And if you’ve already come up with a solution, We would love to hear your story on how you solved it.

Leave a Reply

Your email address will not be published.