Deployment
Laravel Forge
- Server -> New Site
- Root domain: Enter www. version of domain, root domain should be set up to automatically redirect
- Project Type:
General PHP / Laravel - Nginx Template:
Statamic(we’ve created this template - adds proper config for static page generation and asset caching headers) - Check
Use Website Isolation- Remove the www prefix for the Website Isolation Username
- We do not: allow wildcard sub-domains, nor create a database
- Install Repository
- Enter repository and branch
- Install Composer Dependencies: you can uncheck this but it probably doesn’t really matter
- Generate Deploy Key: leave unchecked
- Decide whether or not it makes sense to enable “Quick Deploy”
- Copy paste Deploy Script snippet into Deploy Script. It uses dynamic variables so should work for any site. (see snippet below)
- Check “Make .env variables available to deploy script”
- Edit .env file (Edit Files -> Edit Environment File)
- Current list of variables to potentially update or confirm:
APP_NAME(usually the company name)APP_ENV=productionAPP_DEBUG=falseAPP_URLchange to https version of domainSTATAMIC_LICENSE_KEY- set if client using CPSTATAMIC_STACHE_WATCHER=falseSTATAMIC_STATIC_CACHING_STRATEGY=full(unless decision made otherwise)STATAMIC_API_ENABLEDcan stay false unless the site uses the api in some waySTATAMIC_GIT_ENABLEDtrue if client uses CP IMPORTANT to disable if we’re not using the CPAKISMET_API_KEYset to our Akismet API keySENTRY_LARAVEL_DSNset up Sentry project and enter the URL here (wrap in quotes)CP_ENABLED=falseunless client using CPdangerThis is very important to disable if we are not using the CP
MAIL_MAILER=postmarkPOSTMARK_TOKENset up domain in postmark, enter API key hereMAIL_FROM_ADDRESSset to no-reply@ to the proper sender signature (domain) we’ve set up in postmarkPOSTMARK_MESSAGE_STREAM_IDwe should set up a stream id of “website” in postmark and enter that herecautionensure that
config/mail.phphas the line'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID', 'outbound'),under'transport' => 'postmark',in the postmark array- Comment out every
DB_variable DEBUGBAR_ENABLED=false
- Current list of variables to potentially update or confirm:
- Click Deploy Now to test run your first deploy
- Click “Commands”
- Run
php artisan storage:linkto link the fonts folder so we can serve them
- Run
- Make sure to click SSL and set up the SSL certificate once the domain is pointed at the server
- Click Let’s Encrypt
- Enter the root domain and the www. version (assuming we’re setting up on www.). Separate domains with a comma.
- Public Key Algorithm: leave at default
- Prefer ISRG Root X1 Chain: leave unchecked
- Important Once the SSL Cert is installed, confirm that the cert works for both domains.
- Visit Notifications to add some notification hooks
- 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
- Set up git properly to
- Automatically push on every change
Cloudflare CDN
- 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.
- 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)
- For Glide generated images, make sure you're on Statamic v3.3.30 or higher, and add the
imgpath to aCache EverythingCloudflare 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!"