Pethum Jeewantha
Back to blog

Deploying a Next.js Site to cPanel / Apache

Next.jsDevOpsApache

Not every project needs a Node runtime. For content-driven sites like this portfolio, a static export deploys anywhere - including classic cPanel/Apache shared hosting.

Enable static export

In next.config.ts:

const nextConfig = {
  output: "export",
  trailingSlash: true,
  images: { unoptimized: true },
};

output: "export" emits a plain out/ folder. trailingSlash: true makes Apache serve /about/ as /about/index.html with no rewrite rules.

Build and upload

npm run build   # writes ./out

Then upload the contents of out/ to public_html/ via cPanel File Manager or FTP. That's the whole deploy.

Handle dynamic bits

A static export can't run API routes, so:

  • Contact forms → use a serverless form service (Web3Forms, Formspree) or a small PHP mailer, since Apache runs PHP natively.
  • Caching → add an .htaccess with long cache headers for /_next/static.

The result is a fast, cacheable site with no server to babysit.