Prerequisites
Before setting up custom domains, ensure you have:- A Laravel Forge account with an active subscription
- A DigitalOcean account with API access
- A server configured in Laravel Forge
- Queue workers running on your server
- Laravel Scheduler configured and running
Step 1: Configure Laravel Forge
1.1 Create a Forge API Token
- Log in to Laravel Forge
- Navigate to Account → API → Create New Token
- Give your token a name (e.g., “Custom Domains API”)
- Copy the generated token (you won’t be able to see it again)
1.2 Get Your Server ID
- In Laravel Forge, navigate to your server
- Look at the URL in your browser:
https://forge.laravel.com/servers/{SERVER_ID} - Copy the
SERVER_IDfrom the URL
1.3 Get Your Nginx Template ID
- In your Forge server, go to Nginx Templates
- Create a new template or use an existing one suitable for your application
- The template ID will be in the URL or template details
- Common default template ID is
14570(you can use this initially)
Step 2: Configure DigitalOcean
2.1 Create a DigitalOcean API Token
- Log in to DigitalOcean
- Navigate to API → Tokens/Keys → Generate New Token
- Give your token a name (e.g., “DNS Validation”)
- Set the scopes to Read and Write
- Copy the generated token
The DigitalOcean token is used for DNS validation during SSL certificate provisioning. Keep it secure.
Step 3: Configure Environment Variables
Add the following variables to your.env file:
.env
The
FORGE_NGINX_TEMPLATE can be left as 14570 (default PHP template) or changed to your custom template ID.Step 4: Run Database Migration
The custom domains feature requires a newdomains table. Run the migration:
domains table with the following structure:
Step 5: Configure Queue Workers
Custom domains rely heavily on background jobs. Ensure your queue worker is running:For Development
For Production (with Supervisor)
Create a Supervisor configuration file at/etc/supervisor/conf.d/laravel-worker.conf:
Laravel Forge can automatically configure Supervisor for you. Go to your site’s Queue section and enable the queue worker.
Step 6: Configure Laravel Scheduler
The scheduler runs theapp:check-custom-domain-setup command periodically to monitor and complete pending domain setups.
For Development
Run the scheduler manually:For Production
Add this cron entry (Forge does this automatically):Schedule Configuration
Add to yourroutes/console.php or app/Console/Kernel.php:
Step 7: Test the Configuration
Create a test to verify your Forge connection:Step 8: Configure Your Main Server
8.1 Wildcard SSL Certificate (Optional)
If you want to support subdomains of your main domain (e.g.,*.yourdomain.com), configure a wildcard certificate:
- In Laravel Forge, go to your main site
- Navigate to SSL → LetsEncrypt
- Request a wildcard certificate
8.2 Nginx Configuration
Ensure your main site’s Nginx configuration can handle custom domains. The default configuration should work, but you may need to adjust based on your needs.Step 9: Enable Custom Domains in Team Settings
9.1 Add Domain Field to Team Resource
In your Filament Team resource (app/Filament/Resources/TeamResource.php), add a domain field:
9.2 Add to Table Columns (Optional)
Step 10: Create Team Observer
The team observer triggers domain verification when a domain is added or updated. It should already be in place atapp/Observers/TeamObserver.php:
Verification
After completing the setup:- Log in to your Filament admin panel
- Navigate to Team Settings (or Teams management)
- Add a custom domain to a test team
- Monitor the logs:
tail -f storage/logs/laravel.log - Watch the queue worker process the jobs
- Check the domain record in the database:
Next Steps
- DNS Configuration - Configure DNS records for custom domains
- SSL Certificates - Understand SSL certificate automation
- Troubleshooting - Common issues and solutions
Common Issues
Queue Jobs Not Running
Problem: Domain verification is stuck in pending. Solution: Ensure your queue worker is running:Forge API Errors
Problem: Jobs fail with Forge API errors. Solution: Verify yourFORGE_API_KEY and FORGE_SERVER_ID are correct.
DNS Verification Fails
Problem: DNS verification keeps failing. Solution: Ensure DNS records are properly configured (see DNS Configuration guide).SSL Certificate Issues
Problem: SSL certificates fail to provision. Solution: Verify yourFORGE_DIGITALOCEAN_TOKEN is valid and has proper permissions.
