Deployment
Guide for deploying the Backend
Deploy the Backend
We used Laravel Forge for managing the server because it’s easier for deploying Laravel without manually configuring the Server.
-
Create an account on Laravel Forge.
-
Connect your server to Laravel Forge. We used Hostinger because it’s affordable and offers plenty of RAM, allowing you to deploy your application for development and staging environment. However, you can use any server provider. See: Laravel Forge Supported Server Providers
-
Add your PC’s SSH key to
Your Server -> SSH Keysso you can access the server from your PC. -
Create a site for development and staging environment in Laravel Forge.
Go toServer -> Sites -> Click new site- Root Domain: You can ask the client to create you a dev.capturit.app and staging.capturit.app
- Project Type: Php/Laravel/Symphony (Default)
Advance settings:
- PHP Version: In advance settings, select PHP 8.3.
- Database: You can put capturit_dev or capturit_staging
Click the Add Site button
-
Click the Environment tab
Copy your
.envand paste it in Site Environment section. You should change some of the environment variables:Site Environment APP_ENV=localAPP_ENV=productionAPP_DEBUG=trueAPP_DEBUG=falseAPP_URL=http://localhost:8080APP_URL=https://<Root Domain>DB_DATABASE=capturit_localDB_DATABASE=capturit_devDB_USERNAME=rootDB_USERNAME=forgeDB_PASSWORD=DB_PASSWORD=<Database Password>#For Staging EnvironmentREDIS_DB=0REDIS_DB=1#For Staging EnvironmentREDIS_CACHE_DB=1REDIS_CACHE_DB=2MAIL_FROM_ADDRESS=MAIL_FROM_ADDRESS=<Email address for dev/staging/production>CLOUDFLARE_R2_BUCKET=<local bucket>CLOUDFLARE_R2_BUCKET=<dev/staging/production bucket>SENTRY_LARAVEL_DSN=nullSENTRY_LARAVEL_DSN=<Sentry Project DSN>Click the Save.
-
Click Application tab, click Git Repository
- Configure the Repository and Branch
- Select the Database based on the name you assigned to it in Step 4
- Disable Run Migration
Click the Install Repository and wait for it to install. After installing, enable this Laravel Services:
- Laravel Scheduler
- Laravel Horizon
- Laravel Octane
- Laravel Pulse
Laravel Forge will automatically setup this services for you.
-
Click the Deployments tab
You can enable Quick Deploy if you want, but we usually disabled the Quick Deploy on staging and production environment.
Add this to Deployment Script Section
cd /home/forge/<Root Domain>if [ -f artisan ]; then$FORGE_PHP artisan down$FORGE_PHP artisan backup:rungit pull origin $FORGE_SITE_BRANCH$FORGE_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader( flock -w 10 9 || exit 1echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock$FORGE_PHP artisan passport:keys #run only once$FORGE_PHP artisan migrate --seed --force #run only once#$FORGE_PHP artisan migrate --force #uncomment after running the command above$FORGE_PHP artisan pulse:purge --force$FORGE_PHP artisan optimize:clear$FORGE_PHP artisan optimize$FORGE_PHP artisan storage:link #run only once$FORGE_PHP artisan pulse:restart$FORGE_PHP artisan octane:reload$FORGE_PHP artisan horizon:terminate$FORGE_PHP artisan up;fiClick the Deploy Now button in the upper-right corner of the screen.
-
Click SSL tab
Click on Let’s Encrypt and then click on Obtain Certification. This will add an SSL certificate to your site.
-
Click on the Root Domain above the Public IP. This will redirect you to the website.
-
Add the Firebase JSON file to your project folder
I prefer to use Visual Studio Code for accessing the project file using a remote connection. Requirements:
- Visual Studio Code
- Extension:
- Remote - SSH
-
Open Visual Studio Code.
-
Open the Command Palette by running the following command:
Ctrl + Shift + P -
Type Remote-SSH: Connect to Host and press Enter.
-
Click the Add New SSH Host
-
Enter
ssh forge@server_public_ipand press Enter -
When prompted, enter the Sudo Password and press Enter.
The connection to the server via SSH will begin.
-
Once connected to the server, click Open Folder in the Explorer tab.
A popup will appear. Select the folder named after your Root Domain.
-
Add the Firebase JSON file to the following path:
Storage -> app -> keys
-
Setup Sentry
Open a terminal and connect to the server via SSH
Terminal window ssh forge@server_public_ipInstall the Excimer extension via PECL:
Terminal window sudo pecl install excimerMore info: Sentry for Laravel
This should get the Capturit backend up and running.