server.jsconfiguration instead, see Migrating a Next.js application to the Node.js Selector in cPanel.
Before you begin
Before deploying your application, make sure:- Your cPanel account has a Node.js version that meets your Next.js application’s requirements.
- Your application builds and runs correctly in production mode.
- Your application is configured to use standalone output.
- You can build the application in an environment compatible with the cPanel server, particularly if your application uses native packages such as Sharp.
- Your application can run within the CPU, memory, process, and other resource limits of your hosting plan.
Configure Next.js for standalone output
Next.js can generate a standalone production package containing the files and dependencies required to run your application. In your Next.js project, addoutput: 'standalone' to your next.config.js or next.config.mjs file.
For example:
next.config.mjs, use:
Build your application
Run the production build in your local development or build environment:.next/standalone directory containing a minimal production package and a server.js file that can be used to start the application. The standalone output also includes the dependencies traced as required by the application.
You can test the standalone application locally by running:
📘 Important Theserver.jsgenerated by the standalone build is different from the customserver.jsused in the standard Next.js migration procedure. Use theserver.jsgenerated by your standalone build.
Prepare the application files
The standalone output does not automatically include thepublic directory or .next/static.
If your application uses these directories, copy them into the standalone directory before deploying:
server.js, the traced dependencies, and the required application files.
For example:
📘 Note If you use a monorepo or configureFor more information, see the official Next.js output documentation.outputFileTracingRoot, the generatedserver.jsmay be located in a subdirectory of.next/standalone. Use the location of the generatedserver.jswhen configuring the application in cPanel.
Build for a compatible environment
Standalone output includes dependencies that may contain platform-specific native binaries. This is particularly important when your application uses packages such as Sharp. For example, a build created on macOS or Windows may contain native binaries that are not compatible with a Linux hosting server. For the most reliable deployment:- Build the application on a Linux environment compatible with the hosting server.
- If using CI/CD, use a Linux build environment.
- Use the same Node.js major version for the build and the cPanel application where possible.
- Test the standalone output before uploading it.
Upload the application to cPanel
- Compress the contents of your
.next/standalonedirectory into a ZIP file. - Log in to cPanel.
- Open File Manager.
- Create a directory for your application, for example:
- Upload the ZIP file to the application directory.
- Extract the ZIP file.
- Confirm that the generated
server.jsfile is present in the application directory. - If your application uses
publicor.next/static, confirm that these directories were copied into the standalone output before it was uploaded.
📘 Important
Make sure hidden files and directories, including .next, are included when preparing and uploading your application.
You generally do not need to upload your original project or your full local node_modules directory. The standalone output contains the dependencies traced as required by the application.
Create the Node.js application
After uploading your application:- In cPanel, open Setup Node.js App.
- Click CREATE APPLICATION.
- In the Node.js version list, select a version supported by your Next.js application.
- Set Application mode to Production.
- Set Application root to the directory containing your standalone application.
- Select your domain under Application URL.
- Set Application startup file to:
- Add any required environment variables.
- Click CREATE.
- Click START APP.
📘 Important Do not use Run NPM Install for the standalone deployment package unless your application specifically requires an additional installation step. The standalone output is designed to run using the dependencies included in the generated package.Open your domain in a browser and confirm that the application loads correctly.
Environment variables
Your application may require environment variables such as database connection details, API keys, or other configuration values. Add runtime environment variables through the Node.js application’s environment settings in cPanel. If your application usesNEXT_PUBLIC_* variables, remember that values used by client-side code are generally included during the build process. If you change these values after building the application, you may need to rebuild the application before deploying it again.
Using Sharp for image processing
Next.js applications may use Sharp for image optimization and image processing. Sharp provides prebuilt binaries that include the requiredlibvips components for many common platforms. It does not automatically mean that a separate system-level libvips installation is required.
If your application uses Sharp:
- Make sure
sharpis included in your application’s dependencies. - Install it before creating the production build.
- Build the application in an environment compatible with the production server.
- Test the standalone application before uploading it.
- An incompatible native binary
- A mismatch between the build environment and the hosting environment
- An unsupported Node.js version
- A missing platform-specific dependency
📘 Note Do not assume that installing Sharp alone will resolve every native dependency issue. Sharp selects platform-specific binaries during installation, so the environment used to build and run the application matters.
Application resources and limitations
Building your Next.js application locally does not remove the resources required to run it on the hosting server. Once deployed, a standalone application still runs as a Node.js application and is subject to the resources and process limits of the hosting environment. On shared cPanel hosting, these limits can affect applications that require significant or continuous resources, including:- CPU usage
- Memory usage
- Number of running processes
- Concurrent requests
- Background processing
- Long-running tasks
Scheduled tasks
If your application requires scheduled maintenance or cleanup tasks, you can use cPanel Cron Jobs. For example, a cron job can be used to:- Run scheduled maintenance
- Clean up temporary files
- Remove files that are no longer required
- Run other scheduled application tasks
Redeploy your application
When you need to deploy an updated version:- Build the updated application in your build environment.
- Prepare the new standalone output.
- Copy
publicand.next/staticinto the standalone directory if required. - Create a new ZIP file from the standalone output.
- Upload and extract the updated files to your application directory.
- Make sure the updated
server.jsand.nextfiles are present. - Restart the application in Setup Node.js App.
- Test the application.
.jpg?fit=max&auto=format&n=E2LlsT5gBITvo732&q=85&s=ec11e1673894bdf46663a5d73602eb87)