Laravel Spark is the premier scaffolding package for SaaS applications. It handles subscriptions, billing, teams, and authentication out of the box. But deploying it can trip up even experienced developers. This guide walks you through deploying Laravel Spark on Codemason in minutes.

What is Laravel Spark?

Laravel Spark is a premium Laravel package that provides all the boilerplate code for a SaaS business — Stripe/Braintree billing, subscription plans, team management, and a polished UI. It's maintained by Taylor Otwell, the creator of Laravel itself.

Preparing Your App for Deployment

Before deploying, make sure your application is production-ready:

  • Set APP_ENV=production and APP_DEBUG=false in your .env
  • Run composer install --no-dev --optimize-autoloader
  • Compile your assets with npm run production
  • Cache your config and routes: php artisan config:cache && php artisan route:cache

Dockerizing with Mason

Codemason uses Docker under the hood. The Mason CLI makes Dockerizing your app effortless:

$ npm install codemason --global
$ mason login
$ mason craft laravel

Crafting laravel application with php, mysql, redis
... Wrote Dockerfile
... Wrote docker-compose.yml
... Wrote .gitlab-ci.yml

Laravel Spark requires a queue worker for processing subscription events. Make sure to include a separate service for your queue in your deployment.

Setting Up Your Database

Laravel Spark needs a database for user accounts, subscriptions, and teams. Deploy a MySQL service alongside your app:

$ mason services:create pebble/db     --image mariadb     -p 3306:3306     --env MYSQL_DATABASE=spark     --env MYSQL_USER=spark     --env MYSQL_PASSWORD=secret     --env MYSQL_ROOT_PASSWORD=supersecret     --volume /home/data/mysql:/var/lib/mysql

Configuring Stripe

Add your Stripe keys to your environment. Codemason lets you set environment variables securely through the dashboard or CLI:

STRIPE_KEY=pk_live_your_key
STRIPE_SECRET=sk_live_your_secret
CASHIER_CURRENCY=usd

Running Migrations

Once your containers are running, run your database migrations:

$ mason run spark/web -- php artisan migrate --force

Setting Up the Queue Worker

Laravel Spark dispatches jobs to the queue for processing subscription webhooks. Deploy a dedicated queue worker:

$ mason services:create spark/queue     --image registry.mason.ci/you/spark     --command "php artisan queue:work --tries=3"

And that's it — your Laravel Spark app is live on Codemason. Subscription events are processed, your database is persisted, and your app scales automatically as traffic grows.