Laravel Forge Server Management
Introduction
Laravel Forge is a server management tool that makes deploying and managing PHP applications simple. It handles server provisioning, SSL certificates, queued jobs, and deployment pipelines with minimal configuration.
Forge integrates with major cloud providers including AWS, DigitalOcean, Linode, and Vultr, giving you flexibility in your infrastructure choices.
Server Setup
Create a new server through the Forge dashboard or API. Connect your cloud provider account and select your server specifications:
// Using Forge API to create a server
$forge->servers()->create([
'provider' => 'digitalocean',
'name' => 'production-server',
'size' => 's-2vcpu-4gb',
'region' => 'nyc1',
'php_version' => '8.3'
]);
Forge will automatically install and configure:
- Nginx web server
- PHP (with your chosen version)
- Composer
- Node.js and npm
- MySQL or PostgreSQL
- Redis
SSL Certificates
Forge makes SSL certificates easy with Let's Encrypt integration:
// Install SSL certificate via Forge API
$forge->sites()->createSSL($serverId, $siteId, [
'domains' => ['example.com', 'www.example.com']
]);
Auto-renewal is enabled by default. You can also configure custom certificates:
// Upload custom certificate
$forge->sites()->uploadSSL($serverId, $siteId, [
'certificate' => file_get_contents('cert.pem'),
'key' => file_get_contents('key.pem'),
'chain' => file_get_contents('chain.pem')
]);
Deployment
Configure deployment scripts that run when you push to your repository:
#!/bin/bash
cd /home/forge/example.com
git pull origin main
composer install --no-interaction --no-dev
php artisan migrate --force
php artisan config:cache
php artisan route:cache
npm install && npm run production
(cd /home/forge/example.com && php artisan queue:restart)
Configure deployment triggers in your Forge dashboard for GitHub, GitLab, or Bitbucket.
Queues & Workers
Forge can manage queue workers for processing background jobs:
// Configure queue worker via Forge
$forge->daemons()->create($serverId, [
'command' => 'php artisan queue:work sqs --sleep=3 --tries=3 --max-time=3600',
'user' => 'forge',
'directory' => '/home/forge/example.com',
'processes' => 2,
'wait' => 60
]);
Monitor worker status and manage them directly from the Forge dashboard.
Database Management
Forge provides database management features:
// Create database
$forge->databases()->create($serverId, [
'name' => 'production_db',
'user' => 'db_user',
'password' => 'secure_password'
]);
You can also configure database backups to S3 or other storage providers.
Scheduled Jobs
Forge manages cron jobs through Laravel's scheduler:
// Add scheduled job
$forge->scheduledJobs()->create($serverId, [
'command' => 'php /home/forge/example.com/artisan schedule:run',
'frequency' => '* * * * *',
'user' => 'forge'
]);
Alternatively, use the Supervisord configuration for more complex worker management.
Summary
Laravel Forge simplifies server management for PHP applications. With features like automated SSL, easy deployments, queue management, and database tools, Forge lets you focus on writing code rather than managing infrastructure.
For more information, check out our other tutorials on Laravel Forge CI/CD and Laravel Vapor.