Disclaimer
Please note that some Heroku services are paid. This article is provided for educational purposes only, and TeraCMS is not affiliated with Heroku.Deploying to Heroku
This guide will walk you through deploying TeraCMS to Heroku using GitHub integration for automatic deployments.
Prerequisites
Before you begin, make sure you have:
- A Heroku account
- Your application code pushed to a GitHub repository
- A Procfile in the root of your repository (is already included in the project).
1. Create a Heroku App
First, create a new Heroku application:
- Log in to your Heroku Dashboard
- Click New → Create new app
- Enter a unique app name (e.g.,
your-app-name) - Select a location (choose the one closest to your users)
- Click Create app
2. Connect GitHub Repository
In the deployment tab (second step after creating the app), select GitHub and connect your repository:
- In your Heroku app dashboard, go to the Deploy tab
- Under Deployment method, select GitHub
- Click Connect to GitHub and authorize Heroku to access your GitHub account
- Search for your repository and click Connect
- Optionally, enable Automatic deploys from your main branch
- Click Deploy Branch to trigger your first deployment
3. Configure Environment Variables
Set up all required environment variables in Heroku:
- In your Heroku app dashboard, go to Settings
- Click Reveal Config Vars
- Add all the environment variables from your
.envfile, including:Required Environment Variables
Application
APP_NAME- Your application nameAPP_ENV- Set to your environment name (e.g.,developmentorproduction)APP_KEY- Generate withphp artisan key:generateAPP_DEBUG- Set totrueif you want to see detailed error messages. Set tofalsefor production.
Database
DB_CONNECTION- Set topgsqlfor Heroku PostgresDB_HOST,DB_DATABASE,DB_USERNAME,DB_PASSWORD- You can get this from your Heroku Postgres addon settings (explained in the next section) or your database provider.
Add rest of the environment variables as required by your application from your
.envfile.
4. Configure Database
Using Heroku Postgres (Paid)
- In your Heroku app dashboard, go to the Resources tab
- In the Add-ons section, search for
Heroku Postgres - Select the plan
- Click Submit Order Form
Using your sqlite database
If you are using a sqlite database, remove all the DB values from your config variables. You also need to remove .gitignore file from the database folder. This is not recommended for production environments.
5. Add Node.js Buildpack
- In your Heroku app dashboard, go to the Settings tab
- Click Buildpacks
- Click Add buildpack
- Select
nodejsfrom the list - Click Save
- Redploy your application manually from the deployment tab
You're app should be deployed successfully now. You can verify by clicking on "Open App" button at the top of your dashboard.
Understanding the Procfile
The Procfile in your project root tells Heroku how to run your application:
web: vendor/bin/heroku-php-apache2 public/
worker: php artisan queue:work --sleep=1 --tries=3 --timeout=90
This Procfile defines two process types:
- web: Runs your Laravel application using Apache and PHP. This handles HTTP requests.
- worker: Runs Laravel's queue worker to process background jobs (AI processing, etc.).
Note: The worker dyno is optional but required if you use AI processing due to the long running nature of the jobs.
Enable Worker Dyno
If your application uses AI processing, enable the worker dyno:
- Go to the Overv tab
- In Dyno Formations section, click "configure Dynos"
- Click the pencil icon to edit
- Toggle it On and click Confirm