Blacksmith

Blacksmith was designed for Laravel developers who use Laravel Forge. It keeps a record of what your application's infrastructure looks like as plain files you can read, edit and back up. You can then rebuild a replica of any of your servers or sites quickly, spin up copies of a site on new servers, or load balance a site across several servers.

It requires PHP 8.2+ and supports Laravel 11, 12 and 13.

Warning
Blacksmith assumes you use Laravel Forge. New servers are created on DigitalOcean.
Tip
Create your ENV tokens in your bash profile and you don't have to specify them per project.

Setup

composer require grafite/blacksmith

Then publish the config:

php artisan vendor:publish --provider="Grafite\Blacksmith\BlacksmithProvider"

ENV Variables

BLACKSMITH_FORGE_TOKEN=
BLACKSMITH_SERVER_PROVIDER_TOKEN=     # DigitalOcean, for creating servers
BLACKSMITH_SSH_KEY=~/.ssh/id_ed25519  # must be one of your DigitalOcean SSH keys

Backups go to S3 by default:

BLACKSMITH_AWS_ACCESS_KEY_ID=
BLACKSMITH_AWS_SECRET_ACCESS_KEY=
BLACKSMITH_AWS_DEFAULT_REGION=
BLACKSMITH_AWS_BUCKET=

New droplets default to s-1vcpu-2gb-amd in tor1 running ubuntu-24-04-x64. You can change these with BLACKSMITH_DO_SIZE, BLACKSMITH_DO_REGION, BLACKSMITH_DO_IMAGE, BLACKSMITH_DO_VPC_UUID, BLACKSMITH_DO_BACKUPS, BLACKSMITH_DO_IPV6 and BLACKSMITH_DO_MONITORING, or per server profile (see below). BLACKSMITH_SSH_USER defaults to root.

How It Works

Blacksmith works like a small Terraform for Forge. localize copies a Forge server's configuration into blueprints. The other commands then push those blueprints back to Forge, either to the same server or to brand new ones.

.blacksmith/
  servers/app.json                # server profile: type, PHP, Ubuntu, upload limits, provider size/region
  sites/example.com/site.json     # domain, aliases, repository, SSL, scheduler, workers, redirects, security
  sites/example.com/.env          # the site's env
  sites/example.com/.env.staging  # optional overrides for the "staging" instance only
  sites/example.com/deploy.sh     # deployment script
  state.json                      # which Forge server/site IDs each instance maps to

An instance is a named server, such as prod, staging or example-com-node-1, together with the sites on it. Blueprints never contain Forge IDs, so you can push the same blueprint to as many instances as you like. state.json tracks which Forge server and sites belong to each instance.

Be Careful
Blueprints contain your sites' env files. localize adds .blacksmith to your .gitignore, so make sure you are storing backups in a secure location.

Commands

Command What it does
blacksmith:localizePull a Forge server (and its sites, workers, env, deploy script) into blueprints. Run it again any time to refresh.
blacksmith:make-serverCreate a server, connect it to Forge as a custom server and provision it.
blacksmith:update-serverPush the server profile and site blueprints to Forge.
blacksmith:workersBring queue workers up, down, restart them or show their status.
blacksmith:backupZip .blacksmith and upload it to your backup storage.
blacksmith:instanceCreate a new server with copies of your sites and deploy them, in one step.
blacksmith:balancerPut a load balancer in front of a site.
blacksmith:scaleAdd or remove web nodes behind a site's load balancer.

Localize

php artisan blacksmith:localize {--server=} {--instance=} {--profile=}

Pulls a Forge server and its sites into blueprints. --server is the Forge server ID, --instance names the instance and --profile sets the server profile it is saved as. Run it again any time to refresh the blueprints from Forge.

Make Server

php artisan blacksmith:make-server {instance} {--profile=app} {--ip=} {--private-ip=}

Creates a DigitalOcean droplet from the server profile, connects it to Forge as a custom server, runs Forge's provision script over SSH and waits until the server is ready. There is no manual step. To use a server you already have, pass --ip (and --private-ip) instead.

Update Server

php artisan blacksmith:update-server {instance?} {--site=*} {--only=} {--deploy} {--dry-run}

Pushes the blueprints to Forge. With no instance it updates every instance. If a site is missing from the server it gets created, and only what changed is pushed.

  • --dry-run shows what would change without changing anything.
  • --only limits what's pushed to a comma separated list of sections: server, site, repository, env, deploy, scheduler, workers, ssl, quick_deploy, redirects, security, balancing.
  • --deploy triggers a deployment afterwards.
php artisan blacksmith:update-server prod --only=env,workers --dry-run

Workers

php artisan blacksmith:workers {up|down|restart|status} {instance?} {--site=*}

Manages queue workers. up makes the workers match the blueprint and never duplicates them.

Backup

php artisan blacksmith:backup

Zips .blacksmith and uploads it to the backup_storage disk in the config.

Instance

php artisan blacksmith:instance {name} {--site=*} {--profile=app} {--ip=} {--private-ip=} {--no-deploy}

Creates a new server with copies of your sites and deploys them. With no --site it copies every site blueprint. Pass --no-deploy to skip the first deployment.

Balancer

php artisan blacksmith:balancer {name} {--site=} {--method=round_robin} {--profile=balancer} {--ip=} {--private-ip=}

Creates a load balancer in front of a site, ready to scale it across servers. --method can be round_robin, least_conn or ip_hash.

Scale

php artisan blacksmith:scale {site} {--to=} {--remove=*} {--profile=} {--force}

Adds or removes web nodes behind the site's load balancer. --to is the total number of nodes. --remove=node drains a node and then deletes it, and --force deletes removed servers without asking. New nodes use the primary node's server profile unless you pass --profile.

Copy a Site to a New Server

php artisan blacksmith:localize --server=123456
php artisan blacksmith:instance staging --site=example.com

To change the env for that instance only (for example APP_URL), put the keys in .blacksmith/sites/example.com/.env.staging and run blacksmith:update-server staging --only=env.

Load Balance a Site

php artisan blacksmith:balancer lb --site=example.com
# point example.com's DNS at the balancer, then
php artisan blacksmith:update-server lb --only=ssl
php artisan blacksmith:scale example.com --to=3

The server already running the site becomes the primary node. It is the only node that runs the scheduler and queue workers. New nodes are web-only: they get the same env and deploy script, but no scheduler, workers or certificate, because the balancer terminates SSL.

Warning
Before scaling, make sure sessions, cache, the database and uploads are shared between servers. scale warns you about file, sqlite and localhost settings.

Upgrading from 1.x

Run php artisan blacksmith:localize. It converts the old .blacksmith/{server-id}/config.json folders into blueprints and state, then moves the originals to .blacksmith/legacy. Forge doesn't return security rule passwords, so check the security entries in each site.json after upgrading.

Version 2 removes these commands: setup, build-server, build-site, clone-server, delete-server, update-site, deploy, site-up, site-down, add-worker, add-security, add-redirects, workers-up, workers-down, workers-reset, workers-restart and workers-list.

1.x 2.x
build-server, clone-servermake-server or instance
build-site, update-siteupdate-server --site=
deployupdate-server --deploy
workers-up, workers-down, workers-restart, workers-listworkers up|down|restart|status
add-worker, add-security, add-redirectsEdit site.json, then update-server