Appearance
Deploy to Netlify
Netlify provides another excellent option for deploying Portfolio CMS with automatic deployments and global CDN.
Prerequisites
- GitHub account with your code pushed
- Netlify account (netlify.com)
- PostgreSQL database ready
- S3 storage configured
Step-by-Step Deployment
Step 1: Connect Repository
- Go to app.netlify.com
- Click "Add new site" > "Import an existing project"
- Select "GitHub"
- Authorize and select your repository
Step 2: Configure Build Settings
| Setting | Value |
|---|---|
| Branch to deploy | main |
| Build command | pnpm build |
| Publish directory | .next |
Step 3: Add Environment Variables
Go to Site Settings > Environment Variables:
env
DATABASE_URL=postgresql://user:password@host:5432/database?sslmode=require
PAYLOAD_SECRET=your-super-secret-key-at-least-32-characters
NEXT_PUBLIC_SITE_URL=https://your-site.netlify.app
S3_BUCKET=your-bucket-name
S3_ACCOUNT_ID=your-account-id
S3_ACCESS_KEY_ID=your-access-key
S3_SECRET=your-secret-key
# Optional
RESEND_API_KEY=re_...
RESEND_FROM_EMAIL=...
RESEND_FROM_NAME=...Step 4: Install Next.js Plugin
Add the Next.js Runtime plugin:
- Go to Site Settings > Build & deploy > Plugins
- Search for "@netlify/plugin-nextjs"
- Click Install
Or add to netlify.toml:
toml
[[plugins]]
package = "@netlify/plugin-nextjs"Step 5: Deploy
- Click "Deploy site"
- Wait for build to complete
- Your site is live!
Netlify Configuration File
Create netlify.toml in your project root:
toml
[build]
command = "pnpm build"
publish = ".next"
[build.environment]
NODE_VERSION = "20"
[[plugins]]
package = "@netlify/plugin-nextjs"
# Redirects
[[redirects]]
from = "/admin"
to = "/admin"
status = 200
[[redirects]]
from = "/api/*"
to = "/api/:splat"
status = 200
# Headers
[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "DENY"
X-Content-Type-Options = "nosniff"Custom Domain
Adding a Domain
- Go to Site Settings > Domain management
- Click "Add custom domain"
- Enter your domain name
- Follow the verification steps
DNS Configuration
Option 1: Netlify DNS (Recommended)
- Transfer nameservers to Netlify
- DNS is managed automatically
Option 2: External DNS
Add these records:
Type: A
Name: @
Value: 75.2.60.5Type: CNAME
Name: www
Value: your-site.netlify.appSSL Certificate
Netlify automatically provisions Let's Encrypt certificates.
Build Hooks
Trigger rebuilds from external services:
Create Build Hook
- Site Settings > Build & deploy > Build hooks
- Click "Add build hook"
- Name it and save
- Copy the webhook URL
Use in CMS
Trigger rebuild when content changes:
typescript
// In Payload hook
afterChange: [
async () => {
await fetch(process.env.NETLIFY_BUILD_HOOK, {
method: 'POST',
})
},
],Functions
Netlify Functions handle API routes automatically with the Next.js plugin.
Checking Function Logs
- Go to Functions tab
- Select a function
- View real-time logs
Function Configuration
toml
# netlify.toml
[functions]
directory = ".netlify/functions"
node_bundler = "esbuild"
[functions."*"]
memory = 1024
timeout = 30Environment-Specific Deployments
Branch Deploys
Enable for preview environments:
- Site Settings > Build & deploy > Continuous Deployment
- Enable "Branch deploys"
- Specify which branches to deploy
Deploy Contexts
Different settings per context:
toml
# netlify.toml
# Production
[context.production]
environment = { NODE_ENV = "production" }
# Preview (branch deploys)
[context.deploy-preview]
environment = { NODE_ENV = "preview" }
# Branch-specific
[context.staging]
environment = { NODE_ENV = "staging" }Troubleshooting
Build Fails
View build logs:
- Go to Deploys
- Click failed deploy
- Expand build log
Common issues:
bash
# Plugin not installed
Error: @netlify/plugin-nextjs must be installed
# Fix: Add to netlify.toml or install via UIbash
# Node version mismatch
Error: Node.js version X required
# Fix: Set NODE_VERSION in build environmentbash
# Memory exceeded
Error: JavaScript heap out of memory
# Fix: Increase function memory in netlify.tomlAPI Routes Not Working
- Ensure Next.js plugin is installed
- Check function logs for errors
- Verify environment variables
- Check function timeout settings
Images Not Loading
- Verify S3 credentials
- Check CORS settings
- Ensure Netlify has access to external domains
Slow Builds
- Enable build caching
- Use pnpm for faster installs
- Optimize dependencies
Performance
Enable Asset Optimization
Site Settings > Build & deploy > Asset optimization:
- Bundle CSS
- Minify CSS
- Minify JS
- Compress images
Headers for Caching
toml
[[headers]]
for = "/static/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
[[headers]]
for = "/_next/static/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"Analytics
Netlify Analytics
Premium feature ($9/month):
- Server-side analytics
- No impact on performance
- Privacy-friendly
Alternative
Use Plausible or Google Analytics via Site Settings.