Deploying a Filament Project on DigitalOcean Using Laravel Forge

March 19, 2024 · 5 min read

Laravel Forge and Digital Ocean
When deploying apps, developers look for easy, efficient, and strong features. Since 2012, DigitalOcean has been known for its virtual machines, "Droplets," and services for developers and small-to-medium businesses. Laravel Forge is a top server management tool, making it easy to deploy PHP apps, including Laravel and Filament apps, on cloud hosts like DigitalOcean.
Pre-deployment checklist: Domain and server alignment
Make sure you have a domain with an A Record pointing to your DigitalOcean server before you deploy your Filament app. This connects your domain name to the server’s IP address, letting users access your app.
Accessing Laravel Forge
Go to the Laravel Forge website to start deploying. Log in and select "DigitalOcean" as your provider.
Creating a new site on DigitalOcean
Forge makes it easy to create a new site on DigitalOcean. Enter your root domain and check the PHP version matches your Filament project in the composer.json file. Toggle the Create Database button and write the name of your project’s database.

Connecting your Git repository
Linking your Git repository to Forge is very easy. Enter your repo details, choose the right branch, and Forge will install the Filament app’s code on your DigitalOcean server. The database you created at the previous step is already selected here.

Configuring your Environment settings
Customize your Filament app’s environment within Forge:
Update the APP_NAME
Secure your APP_URL with HTTPS
APP_KEY= should be a unique, random string. If this key is missing, you can generate one by navigating to the command section in Forge and executing "php@8.1 artisan key:generate".
APP_NAME="Your Site"
APP_ENV=production
APP_KEY=
APP_DEBUG=false
APP_URL=https://yoursite.comSecuring your Filament app with SSL
Forge lets you secure your Filament app with free TLS certificates from Let’s Encrypt, ensuring safe connections for your users on DigitalOcean. Go to SSL, click Let’s Encrypt, and wait to see your certificate.

Setting up the Deployment script
Forge’s push-to-deploy feature simplifies the deployment process. There are only a few small changes that we should do. Copy the highlighted section below and add that to your deployment script.
cd /home/forge/yoursite.com
git pull origin $FORGE_SITE_BRANCH
$FORGE_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader
$FORGE_PHP artisan optimize:clear
$FORGE_PHP artisan cache:clear
$FORGE_PHP artisan config:cache
$FORGE_PHP artisan route:cache
$FORGE_PHP artisan view:cache
( flock -w 10 9 || exit 1
echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlockConfiguring the Queue for optimal performance
Follow this section only if your app needs the queue. When you’re working on your web app, some tasks can slow things down during regular requests. The cool thing with Laravel is that you can create queued jobs. These allow time-intensive tasks happen in the background, making your app super responsive and giving your users a smoother experience.
On Laravel Forge, navigate to the Queues section and only change the Maximum Seconds Per Job to 300, that’s more than enough to wait for a job to be finished. Clicking Create will launch your queue worker.
It’s important to configure the queue correctly to ensure that your jobs will run. Within your project’s .env section, set your QUEUE_CONNECTION to redis to make use of its fast, in-memory data store capabilities. Here’s a snippet for clarity:
QUEUE_CONNECTION=redis
REDIS_DATABASE=0If you’re running multiple sites on the same server, assign each one to a distinct Redis database to prevent any overlap. Simply increment the REDIS_DATABASE number accordingly (e.g., 0, 1, 2, etc.).
Sample Environment configuration file
Below, you’ll find a full example of our frequently used configuration, which you can tailor to fit the specific needs of your Filament app:
APP_NAME="Lucky Media"
APP_ENV=production
APP_KEY=
APP_DEBUG=false
APP_URL="https://www.luckymedia.dev"
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_app_database_name
DB_USERNAME=forge
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=redis
REDIS_DATABASE=0
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=""
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
DEBUGBAR_ENABLED=falseKeep in mind: Don’t forget to change your DB_DATABASE field to the database name that you chose at the beginning of this guide.
Before saving the modified Environment file, make sure you tick the option Run php artisan config:cache after saving and that will make sure that the app will be updated with the new changes.
Seeding your Filament admin user
Before deploying the app we need to make sure that we have an admin user for initial login. This can be done by including a production seeder in your app. Make sure that you wrap all seeders within an if condition if you don’t want them to appear in production:
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Hash;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
User::create([
'name' => 'John Doe',
'email' => 'admin@admin.com',
'password' => Hash::make('password'),
'admin' => true,
]);
// these seeders are for local development only
if (App::environment('local')) {
$this->call([
// Other seeders
]);
}
}
}If you already have this on your project then simply head over to Forge and select the Commands tab. Type the following command to seed your database with the admin user.
php artisan db:seed --forceWe need the --force flag because our app is in production. Now we can use the seeded admin user to log in to our app.
Deploying your Filament App
Hit the Deploy Now button and wait for the output. After a successful deployment, your Filament app is up and running on DigitalOcean, ready for users to enjoy. If you navigate to your app link you should see the login screen unless you have created a public page too. Use your admin credentials to log in and navigate through your app.
Conclusion
Laravel Forge gives you a smooth and safe deployment. Enjoy your well-deployed Filament app on DigitalOcean and use Forge’s features for management and monitoring.
Bring Your Ideas to Life 🚀
If you need help with a Laravel project let’s get in touch.
Lucky Media is proud to be recognized as a leading Laravel Development Agency
Technologies

Stay up-to-date
Be updated with all news, products and tips we share!
On this page
- Laravel Forge and Digital Ocean
- Pre-deployment checklist: Domain and server alignment
- Accessing Laravel Forge
- Creating a new site on DigitalOcean
- Connecting your Git repository
- Configuring your Environment settings
- Securing your Filament app with SSL
- Setting up the Deployment script
- Configuring the Queue for optimal performance
- Sample Environment configuration file
- Seeding your Filament admin user
- Deploying your Filament App
- Conclusion
- Bring Your Ideas to Life 🚀

