Web Hosting Knowledge Base Web Hosting Knowledge Base
  • Home
Get Started
Web Hosting Knowledge Base Web Hosting Knowledge Base
Get Started
Web Hosting Knowledge Base Web Hosting Knowledge Base
  • Home
loading
  1. Home
  2. cPanel control panel
  3. cPanel Software
  4. How to migrate a Next.js application to the Node.js Selector in cPanel
Updated on June 14, 2024

cPanel control panel

  • Folder icon closed Folder open iconComplete Guide of log in and log out of cPanel
  • Folder icon closed Folder open iconGetting familiar with the home screen of cPanel
  • Folder icon closed Folder open iconHow to change your cPanel password
  • Folder icon closed Folder open iconHow to change the cPanel language
  • Folder icon closed Folder open iconHow to update contact information and preferences in cPanel
  • Folder icon closed Folder open iconHow to change the cPanel style
  • Folder icon closed Folder open iconHow to change cPanel AutoSSL notifications
  • Folder icon closed Folder open iconcPanel error message: "Your IP address has changed"
  • Folder icon closed Folder open iconThe complete process of User Manager in cPanel
  • Folder icon closed Folder open iconMigrate cPanel accounts from reseller hosting to shared hosting
  • Folder icon closed Folder open iconHow to manage FTP accounts in cPanel
  • Folder icon closed Folder open iconHow to manage backups using cPanel
  • Folder icon closed Folder open iconHow to use Server Rewind to restore files and databases
  • Folder icon closed Folder open iconHow to view disk usage information in cPanel
  • Folder icon closed Folder open iconUsing the cPanel Web Disk Feature
  • Folder icon closed Folder open iconHow to use Server Rewind to restore e-mail
  • Folder icon closed Folder open iconHow to use Git version control in cPanel to install and update a site
  • Folder icon closed Folder open iconHow to reset site content for a managed account
  • Folder icon closed Folder open iconHow to exclude files and directories from cPanel backups
  • Folder icon closed Folder open iconHow to manage e-mail accounts in cPanel
  • Folder icon closed Folder open iconHow to import e-mail accounts and forwarders
  • Folder icon closed Folder open iconHow to change the time zone in webmail
  • Folder icon closed Folder open iconHow to access webmail through cPanel
  • Folder icon closed Folder open iconHow to configure autoresponders in cPanel
  • Folder icon closed Folder open iconHow to import and export webmail contacts
  • Folder icon closed Folder open iconHow to manage mailing lists in cPanel
  • Folder icon closed Folder open iconAccessing webmail clients directly
  • Folder icon closed Folder open iconHow to set up e-mail forwarders
  • Folder icon closed Folder open iconHow to resolve the '550 sender verify failed' error message
  • Folder icon closed Folder open iconExceeding mailbox storage quotas
  • Folder icon closed Folder open iconHow to manage cPanel Mail Exchanger (MX) records
  • Folder icon closed Folder open iconMailing list recipients do not receive list messages
  • Folder icon closed Folder open iconHow to set up DMARC
  • Folder icon closed Folder open iconSynchronizing local clients with webmail calendars and contacts
  • Folder icon closed Folder open iconHow to stop unwanted e-mail using Spam Filters
  • Folder icon closed Folder open iconHow to configure e-mail accounts through webmail
  • Folder icon closed Folder open iconHow to manage e-mail disk usage in cPanel
  • Folder icon closed Folder open iconHow to configure a domain for Google Workspace using cPanel
  • Folder icon closed Folder open iconE-mail messages do not forward to Gmail accounts
  • Folder icon closed Folder open iconHow to filter incoming e-mail messages by IP address
  • Folder icon closed Folder open iconHow to filter unwanted e-mail (spam)
  • Folder icon closed Folder open iconHow to Enable Spam Box
  • Folder icon closed Folder open iconHow to configure e-mail filtering in cPanel
  • Folder icon closed Folder open iconHow to add a Brand Indicators for Message Identification (BIMI) record in cPanel
  • Folder icon closed Folder open iconE-mail messages do not forward to Outlook.com (Hotmail) accounts
  • Folder icon closed Folder open iconHow to manage e-mail deliverability settings in cPanel
  • Folder icon closed Folder open iconDiscontinuation of Barracuda Spam Protection
  • Folder icon closed Folder open iconHow to manage MySQL databases and users in cPanel
  • Folder icon closed Folder open iconHow to manage PostgreSQL databases and users in cPanel
  • Folder icon closed Folder open iconHow to access phpMyAdmin and phpPgAdmin in cPanel
  • Folder icon closed Folder open iconHow to configure remote MySQL access in cPanel
  • Folder icon closed Folder open iconHow to use phpMyAdmin to copy a MySQL database
  • Folder icon closed Folder open iconHow to change the MySQL collation settings in phpMyAdmin
  • Folder icon closed Folder open iconHow to optimize and repair MySQL databases using phpMyAdmin
  • Folder icon closed Folder open iconMySQL passwords do not work after upgrade
  • Folder icon closed Folder open iconHow to delete MySQL database tables using phpMyAdmin
  • Folder icon closed Folder open iconHow to use the cPanel Domains tool
  • Folder icon closed Folder open iconHow to configure redirects in cPanel
  • Folder icon closed Folder open iconAutodiscovery and autoconfiguration DNS records
  • Folder icon closed Folder open iconHow to use the DNS Zone Editor in cPanel
  • Folder icon closed Folder open iconHow to use the cPanel Site Publisher to easily build a website
  • Folder icon closed Folder open iconHow to configure subdomains in cPanel
  • Folder icon closed Folder open iconHow to use log programs in cPanel
  • Folder icon closed Folder open iconHow to view the error log in cPanel
  • Folder icon closed Folder open iconHow to configure and download raw access logs in cPanel
  • Folder icon closed Folder open iconHow to view information about visitors, bandwidth, and resource usage in cPanel
  • Folder icon closed Folder open iconHow to exclude an IP address from AWStats statistics
  • Folder icon closed Folder open iconResource limit information
  • Folder icon closed Folder open iconHow to secure a cPanel-enabled account with a Let's Encrypt SSL certificate
  • Folder icon closed Folder open iconHow to install a third-party SSL certificate with cPanel
  • Folder icon closed Folder open iconHow to install a self-signed SSL certificate in cPanel
  • Folder icon closed Folder open iconHow to configure SSH keys using cPanel
  • Folder icon closed Folder open iconHow to use the IP Blocker in cPanel
  • Folder icon closed Folder open iconHow to configure directory privacy in cPanel
  • Folder icon closed Folder open iconHow to configure leech protection in cPanel
  • Folder icon closed Folder open iconHow to configure hotlink protection in cPanel
  • Folder icon closed Folder open iconHow to manage GnuPG keys in cPanel
  • Folder icon closed Folder open iconHow to secure a cPanel-enabled account with a cPanel SSL certificate
  • Folder icon closed Folder open iconHow to set up AutoSSL on your domain
  • Folder icon closed Folder open iconHow to set up two-factor authentication for cPanel
  • Folder icon closed Folder open iconHow to use Imunify360
  • Folder icon closed Folder open iconHow to manage the ModSecurity module in cPanel
  • Folder icon closed Folder open iconHow to set up cron jobs in cPanel
  • Folder icon closed Folder open iconHow to configure custom Apache handlers in cPanel
  • Folder icon closed Folder open iconHow to create custom error pages in cPanel
  • Folder icon closed Folder open iconHow to configure custom MIME types in cPanel
  • Folder icon closed Folder open iconHow to configure directory indexes in cPanel
  • Folder icon closed Folder open iconHow to install PHP PEAR packages using cPanel
  • Folder icon closed Folder open iconHow to install Perl modules using cPanel
  • Folder icon closed Folder open iconHow to change PHP versions and settings using PHP Selector
  • Folder icon closed Folder open iconHow to use the Python Selector in cPanel
  • Folder icon closed Folder open iconHow to change PHP versions and settings using MultiPHP
  • Folder icon closed Folder open iconHow to use the cPanel Optimize Website feature
  • Folder icon closed Folder open iconHow to create a Node.js application with cPanel using the Node.js Selector
  • Folder icon closed Folder open iconHow to migrate an existing Node.js application to Node.js Selector
  • Folder icon closed Folder open iconHow to use the Application Manager to deploy applications with Passenger
  • Folder icon closed Folder open iconHow to install WordPress using the cPanel WordPress Toolkit
  • Folder icon closed Folder open iconHow to manage WordPress using the cPanel WordPress Toolkit
  • Folder icon closed Folder open iconHow to manage plugins using the cPanel WordPress Toolkit
  • Folder icon closed Folder open iconHow to manage themes using the cPanel WordPress Toolkit
  • Folder icon closed Folder open iconHow to manage multiple sites using the cPanel WordPress Toolkit
  • Folder icon closed Folder open iconHow to stage WordPress with the cPanel WordPress Toolkit
  • Folder icon closed Folder open iconHow to manage WordPress from the command line with the cPanel WordPress Toolkit
  • Folder icon closed Folder open iconHow to configure Web Disk accounts
  • Folder icon closed Folder open iconHow to access Web Disks on Linux and BSD operating systems
  • Folder icon closed Folder open iconHow to access Web Disks on Microsoft operating systems
  • Folder icon closed Folder open iconHow to access Web Disks on Apple operating systems
  • Folder icon closed Folder open iconGetting started with cPanel
    • dfdf
  • Folder icon closed Folder open iconUsing cPanel File Features
    • Using the cPanel File Manager
    • How to restore files, email, and databases using JetBackup
  • Folder icon closed Folder open iconUsing cPanel Mail Features
    • How to forward incoming e-mail messages to a script file
  • Folder icon closed Folder open iconUsing Database Features in cPanel
    • Remote access for MySQL TCP/IP connections on cPanel
  • Folder icon closed Folder open iconUsing the Domain Features in cPanel
  • Folder icon closed Folder open iconUsing the Logging Features in cPanel
  • Folder icon closed Folder open iconSecurity Features in cPanel
    • How to use Imunify Email
  • Folder icon closed Folder open iconAdvanced Features in cPanel
    • How to use Virus Scanner in cPanel
  • Folder icon closed Folder open iconcPanel Software
    • Node.js application error message: "Cannot GET" URL
    • How to migrate an existing application from Node.js Selector to a manual installation
    • How to migrate a Next.js application to the Node.js Selector in cPanel
  • Folder icon closed Folder open iconWordPress Toolkit
    • WordPress Toolkit for resellers
  • Folder icon closed Folder open iconGranting limited cPanel account access to a developer
  • Folder icon closed Folder open iconUsing the Manage Team feature in cPanel

How to migrate a Next.js application to the Node.js Selector in cPanel

Estimated reading: 5 minutes 127 views

You may need to modify some of the following steps to match your particular Next.js application configuration. Such modifications are beyond the scope of Hostvento Hosting support.

Preparing a Next.js project for migration

The following procedure demonstrates how to create a basic Next.js project and prepare it for migration.

If you already have an existing Next.js project, go to step 5.

To create a Next.js project and prepare it for migration, follow these steps:

  1. Make sure you have installed Node.js and npm. If you have not already done so, see the Node.js documentation for information about how to do this on your operating system.
  2. Open a terminal (command prompt) window, and then type the following command:Copynpx create-next-app@latest
  3. A series of questions appears. For the first question What is your project named?, type nextapp.
  4. Accept the default values for all of the remaining questions. Node creates the Next.js project.
  5. In your preferred text editor, create a file named server.js in the application root (nextapp) directory.
  6. Copy the following text and then paste it into the server.js file:
    const { createServer } = require(‘http’) const { parse } = require(‘url’) const next = require(‘next’)   const dev = process.env.NODE_ENV !== ‘production’ const hostname = ‘localhost’ const port = 3000 const app = next({ dev, hostname, port }) const handle = app.getRequestHandler()   app.prepare().then(() => {   createServer(async (req, res) => {     try {       // Be sure to pass `true` as the second argument to `url.parse`.       // This tells it to parse the query portion of the URL.       const parsedUrl = parse(req.url, true)       const { pathname, query } = parsedUrl         if (pathname === ‘/a’) {         await app.render(req, res, ‘/a’, query)       } else if (pathname === ‘/b’) {         await app.render(req, res, ‘/b’, query)       } else {         await handle(req, res, parsedUrl)       }     } catch (err) {       console.error(‘Error occurred handling’, req.url, err)       res.statusCode = 500       res.end(‘internal server error’)     }   })     .once(‘error’, (err) => {       console.error(err)       process.exit(1)     })     .listen(port, () => {       console.log(`> Ready on http://${hostname}:${port}`)     }) })
  7. Save your changes to the server.js file.
    By default, Next.js applications run on the server included with Next.js. To integrate a Next.js application with the cPanel Node.js Selector however, you must run a custom server using the code above.
  8. Open the package.json file in your preferred text editor. Locate the “scripts” section and replace the existing “start” line with the following line:
    “start”: “NODE_ENV=production node server.js”,
  9. Save your changes to the package.json file.
  10. At the command prompt, change to the nextapp directory, and then type the following command:
    Copynpm run build
  11. In the nextapp directory, type the following command:
    Copyzip -r ../nextapp.zip . –exclude “.git/*” .gitignore “node_modules/*” README.md
    • This command compresses the project (excluding unnecessary files and directories) and saves it in the nextapp.zip file in the parent directory.
    • If you do not have the zip command-line program installed, use your operating system’s file manager to create the nextapp.zip file instead.

You are now ready to create a Node.js application on your hosting account in cPanel, and migrate the Next.js project to it.

Migrating a Next.js project to cPanel

To migrate a Next.js project to cPanel’s Node.js Selector, follow these steps:

  1. Log in to cPanel.If you do not know how to log in to your cPanel account, please see this article.
  2. Set up your application files in the correct location:
    • Using the File Manager in cPanel, upload to your account the nextapp.zip file you created in the previous procedure.
    • In the File Manager, create a directory in the public_html directory named nextapp.
    • In the File Manager, extract the nextapp.zip file to the public_html/nextapp directory.
  3. Create a Node.js application to run the Next.js application:
    • On the Tools page, in the Software section, click Setup Node.js App:cPanel - Software - Setup Node.js App
    • On the Node.js selector page, click CREATE APPLICATION to start the application setup:
    • In the Node.js version list box, select the Node.js version.
      The version should match as closely as possible the Node.js version you used to create the application in the previous procedure. Next.js requires Node.js version 18.17 or higher.
    • In the Application mode list box, select Production.
    • In the Application root text box, type nextapp.
    • In the Application URL list box, select your domain and leave the text box empty.
    • In the Application startup file text box, type server.js.
    • Click CREATE. cPanel creates the application:
      cPanel - Node.js Selector - Next.js application configuration
  4. Click STOP APP.
  5. Click Run NPM Install.
    • The NPM installation process may take a few minutes to complete.
    • If the Run NPM Install option is disabled (grayed out), try going back to the cPanel home screen, and then on the Tools page, click the Setup Node.js App icon again. This forces cPanel to re-scan all of the Node.js applications installed on your account.
  6. When the NPM installation process is complete, click START APP.
  7. In your web browser, go to example.com, where example.com represents your domain name. The Next.js application should appear:
    Next.js - Default welcome page

Still stuck? How can we help?

How can we help?

Was this page helpful? Yes No

Share this Doc

How to migrate a Next.js application to the Node.js Selector in cPanel

Or copy link

Clipboard Icon
CONTENTS
Leaf Illustration

© 2023 All Rights Reserved by Hostvento