Introduction
Deploying a Filament panel to production requires several steps to ensure optimal performance and security. This guide covers best practices for production deployments.Pre-deployment checklist
Before deploying, ensure you’ve completed these steps:Component caching
Filament automatically caches discovered resources, pages, and widgets in production. This significantly improves performance.Manual caching
Cache components manually:Clearing the cache
When you add or remove components, clear the cache:Cache location
Component cache is stored inbootstrap/cache/filament/panels/{panel-id}.php.
Asset compilation
Always compile assets for production:- Minifies CSS and JavaScript
- Optimizes for production
- Removes source maps
- Applies PostCSS transformations
Custom themes
If using custom themes with Vite:Environment variables
Key environment variables for production:Performance optimization
Enable OPcache
Ensure OPcache is enabled in your PHP configuration:Use Redis for caching
Database optimization
Add indexes to frequently queried columns:Enable SPA mode
For faster navigation:Queue long-running tasks
Move heavy operations to queues:Security considerations
HTTPS
Always use HTTPS in production. Force HTTPS in your web server configuration.Rate limiting
Add rate limiting to prevent abuse:CSRF protection
Ensure CSRF protection is enabled (Laravel default).Content Security Policy
Add CSP headers to prevent XSS attacks:Disable registration
Disable public registration in production if not needed:Strong passwords
Enforce strong password requirements:Database setup
Run migrations
--force flag is required in production.
Seed initial data
If needed, seed initial data:Backup strategy
Implement regular database backups:spatie/laravel-backup.
File permissions
Set correct file permissions:Web server configuration
Nginx
Example Nginx configuration:Apache
Ensuremod_rewrite is enabled and .htaccess is configured:
Deployment automation
Using Laravel Forge
Laravel Forge provides one-click deployments:- Connect your Git repository
- Configure deployment script:
Using Deployer
Exampledeploy.php for Deployer:
Monitoring
Error tracking
Use error tracking services:.env:
Performance monitoring
Monitor application performance:- Laravel Telescope (development)
- New Relic (production)
- Blackfire (profiling)
Uptime monitoring
Use services like:- Pingdom
- UptimeRobot
- Oh Dear
Zero-downtime deployment
For zero-downtime deployments:- Use a deployment tool (Forge, Envoyer, Deployer)
- Keep queue workers running
- Use
php artisan downonly when necessary - Enable maintenance mode with secret bypass: