Skip to main content

Deployment

Laravel Forge

  1. Server -> New Site
    1. Root domain: Enter www. version of domain, root domain should be set up to automatically redirect
    2. Project Type: General PHP / Laravel
    3. Nginx Template: Statamic (we’ve created this template - adds proper config for static page generation and asset caching headers)
    4. Check Use Website Isolation
      1. Remove the www prefix for the Website Isolation Username
    5. We do not: allow wildcard sub-domains, nor create a database
  2. Install Repository
    1. Enter repository and branch
    2. Install Composer Dependencies: you can uncheck this but it probably doesn’t really matter
    3. Generate Deploy Key: leave unchecked
  3. Decide whether or not it makes sense to enable “Quick Deploy”
  4. Copy paste Deploy Script snippet into Deploy Script. It uses dynamic variables so should work for any site. (see snippet below)
    1. Check “Make .env variables available to deploy script”
  5. Edit .env file (Edit Files -> Edit Environment File)
    1. Current list of variables to potentially update or confirm:
      1. APP_NAME (usually the company name)
      2. APP_ENV=production
      3. APP_DEBUG=false
      4. APP_URL change to https version of domain
      5. STATAMIC_LICENSE_KEY - set if client using CP
      6. STATAMIC_STACHE_WATCHER=false
      7. STATAMIC_STATIC_CACHING_STRATEGY=full (unless decision made otherwise)
      8. STATAMIC_API_ENABLED can stay false unless the site uses the api in some way
      9. STATAMIC_GIT_ENABLED true if client uses CP IMPORTANT to disable if we’re not using the CP
      10. AKISMET_API_KEY set to our Akismet API key
      11. SENTRY_LARAVEL_DSN set up Sentry project and enter the URL here (wrap in quotes)
      12. CP_ENABLED=false unless client using CP
        danger

        This is very important to disable if we are not using the CP

      13. MAIL_MAILER=postmark
      14. POSTMARK_TOKEN set up domain in postmark, enter API key here
      15. MAIL_FROM_ADDRESS set to no-reply@ to the proper sender signature (domain) we’ve set up in postmark
      16. POSTMARK_MESSAGE_STREAM_ID we should set up a stream id of “website” in postmark and enter that here
        caution

        ensure that config/mail.php has the line 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID', 'outbound'), under 'transport' => 'postmark', in the postmark array

      17. Comment out every DB_ variable
      18. DEBUGBAR_ENABLED=false
  6. Click Deploy Now to test run your first deploy
  7. Click “Commands”
    1. Run php artisan storage:link to link the fonts folder so we can serve them
  8. Make sure to click SSL and set up the SSL certificate once the domain is pointed at the server
    1. Click Let’s Encrypt
    2. Enter the root domain and the www. version (assuming we’re setting up on www.). Separate domains with a comma.
    3. Public Key Algorithm: leave at default
    4. Prefer ISRG Root X1 Chain: leave unchecked
    5. Important Once the SSL Cert is installed, confirm that the cert works for both domains.
  9. Visit Notifications to add some notification hooks
    1. Teams Webhook URL
      https://wemaketechsimple.webhook.office.com/webhookb2/bcca645b-9ec7-42ce-a4f7-fce4680a7e1b@21e8c5a8-8f71-4dd5-8493-61de9685a9bd/IncomingWebhook/ff2e981900284bcead30d14bc0adb507/7db6747a-432f-47ee-9de3-4e4397eb95d0

If we or the client is using the CP in production

WIP

  1. Set up git properly to
    1. Automatically push on every change

Cloudflare CDN

  1. Important preface: in order to use Cloudflare's CDN, you must be "orange clouded" (proxy DNS through them). I need to do more research on the Let's Encrypt SSL cert with this. I do know that if we disable the DNS proxy, then get the cert, we can then re-enable the proxy. I just need to make sure that it can get renewed this way.
  2. With our nginx template, all font files, css, js, etc. will automatically get cached (due to no cookies being on the response and a proper cache-control header)
  3. For Glide generated images, make sure you're on Statamic v3.3.30 or higher, and add the img path to a Cache Everything Cloudflare page rule (e.g. *test.interquest.dev/img/*)

Snippets

Deploy Script

if [[ $FORGE_DEPLOY_MESSAGE =~ "[SKIP]" ]]; then
echo "Skipping deployment upon commit message request."
exit 1
fi

if [[ $FORGE_DEPLOY_MESSAGE =~ "[BOT]" ]]; then
echo "AUTO-COMMITTED ON PRODUCTION. NOTHING TO DEPLOY."
exit 0
fi

cd $FORGE_SITE_PATH

# git reset --hard && git clean -df
git pull origin $FORGE_SITE_BRANCH

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

npm ci && npm run build

( 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
# fi


php artisan cache:clear
php artisan config:cache
php artisan route:cache
php artisan statamic:stache:warm
php artisan statamic:search:update --all
php artisan statamic:static:clear
php artisan google-fonts:fetch
php artisan statamic:assets:generate-presets

# if [[ $STATAMIC_STATIC_CACHING_STRATEGY == "full" ]]; then
# php artisan statamic:static:warm
# fi

echo "${APP_NAME} is deployed!"