Jonas Siewertsen

My personal hosting choice for Statamic 3 projects

Statamic 3 hosting with Laravel Forge

One option to host your Statamic site is Laravel Forge in combination with DigitalOcean, AWS or others. It has been designed to fulfill the needs of a Laravel application, so it's a good thing that Statamic is building on top of Laravel.


JANUARY 23RD, 2020

Introduction

You do need a Laravel Forge account. If you never used Forge before, you can go with the trial mode for 14 days.

Add at least one server to Forge. Personally I am using DigitalOcean, but that is only my personal choice.

Support

This article is 100% free, without any ads or personal tracking.

If you want to support me, please use one of my affiliate links:

This will help me write more articles in the future and keeping this page ad free. Does that sound fair to you?

Create your server

Log in to Laravel Forge and create a server:

  1. Server Size: The smallest one with 1GB RAM & 1CPU is more than enough. You can always upgrade later if needed.

  2. PHP: Version > 7.2

  3. Database: Not needed for Statamic.

  4. Provision As Load Balancer: Nope

  5. Weekly Backups: Your Choice.

Connect your repository

Use your version control to upload all files and later changes, to your server.

  1. Add the SSH key to your repository

  2. Enter your repository name

  3. Branch: Normally 'master'

  4. Install Composer Dependencies: Yes

Deploy Script


We want to tweak it a little bit, so we don't need to worry about caching, old glide presets ...

Your default should look something like that

cd /home/forge/default
git pull origin master
composer install --no-interaction --prefer-dist --optimize-autoloader

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

The first bit is fine, even if yours can look a little different. It does depend on the PHP Version, but normally you can stay with the forge default.

Let's add a little more spices to it:

cd /home/forge/default
git pull origin master
composer install --no-interaction --prefer-dist --optimize-autoloader

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

php artisan optimize
php please cache:clear
php please stache:clear
php please glide:clear

General (line 1)

All following commands need to be run in the root directory of your project folder. Let's go there, in our case default.

Git (line 2)

Pulling the latest changes from your repository

Composer (line 3)

Will install all packages or updates on your production server.

As a best practice, run composer update locally and test it. Afterward, you can push your updated composer.json and/or composer.lock it into your version control and deploy it with Forge.

PHP FPM (line 5-6)

Will restart the FPM

Artisan Optimize (link 8)

Will merge config files, Laravel routes, views etc ...

Please clear

Will delete cache, the stache and glide presets from Statamic, so that all made changes will take effect.

Set up your environment file

This set up depends on your unique application of course. It could look like this:

APP_NAME="Your Application Name"
APP_ENV=production
APP_KEY=yourpersonalkey
APP_DEBUG=false
APP_URL=http://yoururl.com

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=redis

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

You need to change those settings of course. Generate a key etc ...

Redis as queue worker

Setting up a Redis queue worker in Laravel Forge is a breeze and will give your application a lot of value, by pushing jobs & queues into the background. Extremely interesting if sending mails with Statamic or in case you are using Spock (will soon be available for Statamic v3).

Remember to require the extension in your composer file.

composer require predis/predis

Open the Queue Link in your Laravel Forge project and start a new worker:

You can customize those settings if needed, but for a normal queue worker, you can go with the default. What i would recommend:

More Information on using Redis with Laravel.

SSL

Forge is taking care of SSL for free. First you need to point your domain to the server, change from default to your domain address.

DigitalOceans tutorial

Afterward, you can choose Let's encrypt for your SSL certificate. It's free and a good choice for a standard homepage.

NPM (optional)

If you don't want to run npm run production before every deploy, Forge can take care of that

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

npm install
npm run production

php artisan optimize
(...)

To do so, you should have added your automatically created files to your .gitignore file. Just extend the file with your css and js file name.

/public/css/app.css
/public/js/app.js

Max File Upload Limit

I would recommend adjust the standard upload limit.

Go to your Server PHP Settings in Laravel Forge and change it there.

More

You can do even more, but this should be a good standard setup and get you going. Things that could me interesting as well:

Support

Did you like this article? Let me know on Twitter and if you want, you can support me by using one of my affiliate links. Just if you want!