Skip to main content

Production & Deployment (Laravel Forge)

You have built your app, tested it locally, and now you are ready to deploy it to a production server. This guide will walk you through the process of provisioning and deploying your app to a production server using Laravel Forge.

Saasykit also supports deploying your app using Deployer, a deployment tool that allows you to deploy your app with zero downtime, rollbacks, and many more features, for more info on how to use Deployer, check the Deployer docs.

Prepare your serverโ€‹

You'd need to create a Laravel Forge account to prepare your server. So make sure to do that before proceeding.

  1. Once you login to Laravel Forge, connect your source control provider (e.g. GitHub, GitLab, Bitbucket) to Laravel Forge.

    Source control
  2. Select the cloud provider where you want to deploy your app (e.g. DigitalOcean, Akamai, AWS, Vultr or Hetzner).

    Depending on your cloud provider, you will need to create an API key/secret and enter them in Laravel Forge. This will basically allow Laravel Forge to create and manage servers on your behalf.

    Server providers
  3. Create a new server on Laravel Forge. Depending on the cloud provider, you can choose the server size, region, etc.

    Make sure to select the server type. If you are starting out, choose "App Server" as the server type, as it will come with PHP, MySQL, Redis, Memcached, and Nginx pre-installed.

    In the future you can add a separate server for the database, cache, etc., as your app grows.

    Create new server
  4. Copy the server credentials (Sudo Password & Database Password) to a safe place, as you might need them later.

    Server credentials
  5. Wait until the server is provisioned. โ˜•๏ธ

  6. Once the server is provisioned, it will have a "default" site created for you, but you would need to create a new site for your app, which will be used to map your domain name to the app on the server.

Enter the domain name of your app in the "Root Domain" field, and click "Add Site".

Add site

Make sure that you have pointed your domain (on your domain registrar) to the server's IP address before adding the site.

  1. Once the site is added, click on "Install Application", then on the "Install repository" view, select the repository that you want to deploy (if you forked SaaSykit, then it'll be your-username/saasykit), choose branch to deploy (typically main) and click "Install Repository".

    Install app Install Repository

8.From the left menu, click "Deployments", then paste in the following deployment script:

cd /home/forge/default
git pull origin $FORGE_SITE_BRANCH

$FORGE_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader

( flock -w 10 9 || exit 1
echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock

if [ -f artisan ]; then
$FORGE_PHP artisan migrate --force
$FORGE_PHP artisan db:seed --force
$FORGE_PHP artisan app:generate-sitemap

$FORGE_PHP artisan horizon:terminate

npm ci && npm run build

Then click "Update".

  1. Click on "Deploy Now" to deploy your app.

  2. Once the deployment is done, you can visit your app's domain to see your app running. And that's it! You have successfully deployed your app to a production server using Laravel Forge. ๐ŸŽ‰


If you faced any issue during the deployment, you can check the logs by clicking on "Logs" in the left menu to see what went wrong.