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.
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:
Server Size: The smallest one with 1GB RAM & 1CPU is more than enough. You can always upgrade later if needed.
PHP: Version > 7.2
Database: Not needed for Statamic.
Provision As Load Balancer: Nope
Weekly Backups: Your Choice.
Connect your repository
Use your version control to upload all files and later changes, to your server.
Add the SSH key to your repository
Enter your repository name
Branch: Normally 'master'
Install Composer Dependencies: Yes
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 ...
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:
Set "Maximum Seconds Per Job"
Set "Maximum Tries"
Set "Run Worker As Daemon" to true
More Information on using Redis with Laravel.
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.
Afterward, you can choose Let's encrypt for your SSL certificate. It's free and a good choice for a standard homepage.
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.
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.
You can do even more, but this should be a good standard setup and get you going. Things that could me interesting as well:
PHP Settings: OPCache for production
PHP Settings: Max execution time
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!