From Zero to Production in Laravel

In this note, I will take you through my personal journey of setting up a Laravel project from scratch and taking it to production. I'll share the tools and technologies I used, including Forge, Nova, and GitHub Actions. Instead of lengthy explanations, I'll provide a simple checklist for easy reference in your future projects.

Objective

  • To make a SaaS, optimizing the project to be ready for Production.

Environment

  • MacBook Air (M1, 2020)
  • macOS Monterey 12.6.5
  • Visual Studio Code 1.79.2

Tools

  • Laravel Octane
  • Laravel Forge
  • Laravel Nova
  • Laravel Spark

To Read

1. Create Laravel Project, and install Octane

composer create-project laravel/laravel example-app

composer require laravel/octane

php artisan octane:install

2. Create GitHub repository, add the project into GitHub as first commit

cd example-app
echo "# example-app" > README.md
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/yourgithub/example-app.git
git push -u origin main

3. Add New Site in your Forge account. Remember to Laravel Octane for Project Type.

4. Setup encrypted environment files. Staging and Production

cp .env.example .env.staging
cp .env.example .env.production

# Replace the variable accordingly
php artisan env:encrypt --env=staging --force
php artisan env:encrypt --env=production --force

# Copy Key to Forge

Reference: https://laravel.com/docs/10.x/configuration#encrypting-environment-files

5. Add .env.staging in .gitignore

6. Add following command in Forge's Deploy Script

php artisan env:decrypt --env=staging --filename=.env --force
php artisan env:decrypt --env=production --filename=.env --force

7. Setup Daemon for Octane, following steps in Forge

8. At this step, default welcome page should be working.

9. Setup GitHub Actions for CI/CD.

10. Install Nova

11. Install Spark