What you will learn
- Build a production version of a Next.js site and deploy it from GitHub
- Set environment variables on a hosting platform
- Connect a custom domain with DNS records and confirm HTTPS works
Deployment means putting your site on a server that is always online. First, run npm run build locally to check that the production build succeeds without errors. Several hosting platforms can deploy a Next.js project straight from a GitHub repository, and some offer free tiers for personal projects. Once connected, each push to the main branch triggers a new deployment automatically.
Your .env file is not in the repository, so the hosting platform does not have your secrets. Add each environment variable in the platform's project settings instead, and redeploy. Many platforms also create a preview deployment for each branch or pull request, with its own temporary address, so you can check changes on a real server before they reach the live site.
To use your own domain, buy it from a registrar, add it in the hosting platform's settings and create the DNS records the platform asks for, usually an A record or a CNAME record. DNS changes can take some time to spread. Most hosting platforms issue an SSL certificate automatically, so your site loads over HTTPS. Check that the address with and without www both work.


