Skip to main content

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:
1

Environment configuration

Set APP_ENV=production and APP_DEBUG=false in your .env file.
2

Generate application key

3

Configure database

Update database credentials in .env for your production database.
4

Run migrations

5

Cache configuration

6

Cache Filament components

7

Build assets

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 in bootstrap/cache/filament/panels/{panel-id}.php.

Asset compilation

Always compile assets for production:
This:
  • Minifies CSS and JavaScript
  • Optimizes for production
  • Removes source maps
  • Applies PostCSS transformations

Custom themes

If using custom themes with Vite:
Ensure the built assets are committed or deployed with your application.

Environment variables

Key environment variables for production:

Performance optimization

Enable OPcache

Ensure OPcache is enabled in your PHP configuration:

Use Redis for caching

Install Redis PHP extension:

Database optimization

Add indexes to frequently queried columns:

Enable SPA mode

For faster navigation:

Queue long-running tasks

Move heavy operations to queues:
Use Supervisor to keep queue workers running.

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

The --force flag is required in production.

Seed initial data

If needed, seed initial data:

Backup strategy

Implement regular database backups:
Use packages like spatie/laravel-backup.

File permissions

Set correct file permissions:
Ensure your web server user owns the files:

Web server configuration

Nginx

Example Nginx configuration:

Apache

Ensure mod_rewrite is enabled and .htaccess is configured:

Deployment automation

Using Laravel Forge

Laravel Forge provides one-click deployments:
  1. Connect your Git repository
  2. Configure deployment script:

Using Deployer

Example deploy.php for Deployer:

Monitoring

Error tracking

Use error tracking services:
Configure in .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:
  1. Use a deployment tool (Forge, Envoyer, Deployer)
  2. Keep queue workers running
  3. Use php artisan down only when necessary
  4. Enable maintenance mode with secret bypass:
Access your site during maintenance:

Post-deployment

After deployment:
1

Verify installation

Check that the site loads correctly and all features work.
2

Test authentication

Verify login, registration, and password reset work.
3

Check logs

Review storage/logs/laravel.log for errors.
4

Monitor performance

Use monitoring tools to track performance metrics.