Introduction
Deploying a fullstack Laravel Breeze API + Next.js application requires careful consideration of both backend and frontend infrastructure. This guide provides an overview of deployment strategies, hosting options, and production requirements.Deployment Architecture
Your application consists of two separate components that must be deployed independently:- Backend (Laravel API): Requires PHP 8.2+ hosting with database support
- Frontend (Next.js): Requires Node.js hosting or static hosting depending on rendering strategy
Communication Flow
Hosting Options
Backend Hosting
Traditional VPS
Full control over server configuration. Ideal for complex requirements.
- DigitalOcean, Linode, Vultr
- AWS EC2, Google Compute Engine
- Requires server management skills
Platform as a Service
Managed PHP hosting with automatic scaling and maintenance.
- Laravel Forge + DigitalOcean
- Heroku (with PHP buildpack)
- Platform.sh, Laravel Cloud
Serverless
Pay-per-request pricing with automatic scaling.
- AWS Lambda (via Bref)
- Vapor (Laravel’s serverless platform)
- Google Cloud Run
Shared Hosting
Budget-friendly option for small applications.
- cPanel hosting with PHP 8.2+
- Limited control and resources
- Not recommended for production
Frontend Hosting
Vercel
Optimized for Next.js with zero configuration.
- Automatic deployments from Git
- Global CDN and edge functions
- Free tier available
Netlify
Static and SSR hosting with simple setup.
- Git-based deployments
- Form handling and functions
- Free tier available
Custom Server
Full control with Node.js hosting.
- VPS with PM2 or Docker
- Requires server management
- More configuration needed
Static Hosting
If using static export only.
- AWS S3 + CloudFront
- Cloudflare Pages
- GitHub Pages (with limitations)
Production Requirements
Backend Requirements
Server Requirements
Server Requirements
- PHP 8.2 or higher
- Composer 2.x
- MySQL 8.0+ or PostgreSQL 13+
- Redis (optional, for caching and queues)
- Supervisor (for queue workers)
- Cron access (for scheduled tasks)
PHP Extensions
PHP Extensions
- BCMath
- Ctype
- cURL
- DOM
- Fileinfo
- JSON
- Mbstring
- OpenSSL
- PCRE
- PDO
- Tokenizer
- XML
Web Server
Web Server
- Nginx (recommended) or Apache
- SSL certificate (Let’s Encrypt)
- HTTP/2 support
- Gzip/Brotli compression
Frontend Requirements
- Node.js 18+ (LTS recommended)
- npm, pnpm, or yarn
- Environment variables configured
- HTTPS enabled (required for Sanctum cookies)
HTTPS Requirements
Why HTTPS is Required
- Laravel Sanctum Security: Sanctum uses secure, httpOnly cookies for authentication
- Cookie Transmission: Browsers block secure cookies over HTTP
- API Communication: Cross-origin requests require secure connections
- Modern Standards: HTTPS is a baseline security requirement
SSL Certificate Options
- Let’s Encrypt: Free, automated SSL certificates
- Cloudflare: Free SSL with CDN and DDoS protection
- Commercial Certificates: Wildcard and extended validation options
Production Checklist
Before deploying to production, ensure you’ve completed these tasks:Backend Checklist
Environment Configuration
- Set
APP_ENV=production - Set
APP_DEBUG=false - Generate strong
APP_KEY - Configure database credentials
- Set proper
APP_URLandFRONTEND_URL
Security Hardening
- Review CORS configuration
- Configure trusted hosts
- Set secure session settings
- Enable CSRF protection
- Configure rate limiting
Performance Optimization
- Run
composer install --optimize-autoloader --no-dev - Cache configuration:
php artisan config:cache - Cache routes:
php artisan route:cache - Cache views:
php artisan view:cache - Enable OPcache
Database Setup
- Run migrations:
php artisan migrate --force - Seed production data if needed
- Configure database backups
- Set up read replicas if needed
Queue and Cron
- Configure queue workers with Supervisor
- Set up cron job for scheduler
- Test queue processing
- Monitor queue failures
Frontend Checklist
Environment Configuration
- Set
NEXT_PUBLIC_BACKEND_URLto production API URL - Configure any additional environment variables
- Remove development-only variables
Build Configuration
- Choose rendering strategy (SSR vs Static Export)
- Configure output settings in
next.config.js - Optimize images and assets
- Enable production optimizations
Security
- Review API endpoint configurations
- Ensure no sensitive data in client code
- Configure Content Security Policy
- Enable security headers
Deployment Strategies
1. Separate Deployments (Recommended)
Deploy backend and frontend independently:- Backend: Deploy to PHP hosting (Forge, VPS, etc.)
- Frontend: Deploy to Vercel, Netlify, or custom Node.js server
- Advantages: Better separation of concerns, independent scaling, easier rollbacks
2. Monolithic Deployment
Deploy both on the same server:- Backend serves API at
/api - Frontend served by Node.js or built as static files
- Advantages: Simpler infrastructure, single deployment
- Disadvantages: Harder to scale, more complex configuration
3. Containerized Deployment
Use Docker for both services:- Separate containers for Laravel and Next.js
- Orchestrate with Docker Compose or Kubernetes
- Advantages: Consistent environments, easy scaling, portability
Domain Configuration
Recommended Setup
Alternative Setup
Environment Variables
Ensure these critical environment variables are set:Backend (.env)
Frontend (.env.production)
Post-Deployment Testing
After deployment, verify:- Backend
- Frontend
- API health check endpoint responds
- Database connection works
- Authentication endpoints functional
- Queue workers processing jobs
- Scheduled tasks running
- SSL certificate valid
- CORS headers present
Next Steps
Backend Deployment
Deploy your Laravel API to production
Frontend Deployment
Deploy your Next.js application
Environment Configuration
Configure production environment variables
Backend Testing
Learn about testing your Laravel backend