# Heroku
This is a step-by-step guide for deploying a Strapi v3 or v4 project on Heroku (opens new window). Databases that work well with Strapi and Heroku are discussed in the instructions on how to get started.
# Heroku Install Requirements
- You must have Git installed and set-up locally (opens new window).
- You must have a free Heroku account (opens new window) before doing these steps.
If you already have the Heroku CLI installed locally on your computer, skip to Login to Heroku.
# 1. Heroku CLI Installation
Download and install the Heroku CLI
for your operating system:
# 2. Login to Heroku from your CLI
Next, you need to login to Heroku from your computer.
heroku login
Follow the instructions and return to your command line.
# 3. Create a new project (or use an existing one)
Create a new Strapi project (if you want to deploy an existing project go to step 4).
Path: ./
💡 TIP
When you use --quickstart
to create a Strapi project locally, a SQLite database is used which is not compatible with Heroku. Therefore, another database option must be chosen.
# 4. Update .gitignore
Add the following line at end of .gitignore
:
Path: ./my-project/.gitignore
package-lock.json
Even if it is usually recommended to version this file, it may create issues on Heroku.
# 5. Init a Git repository and commit your project
Init the Git repository and commit your project.
Path: ./my-project/
cd my-project
git init
git add .
git commit -m "Initial Commit"
# 6. Create a Heroku project
Create a new Heroku project.
Path: ./my-project/
heroku create
You can use heroku create custom-project-name
, to have Heroku create a custom-project-name.heroku.com
URL. Otherwise, Heroku will automatically generate a random project name (and URL) for you.
💡 TIP
If you have a Heroku project app already created, you would use the following step to initialize your local project folder:
Path: ./my-project/
heroku git:remote -a your-heroku-app-name
Your local development environment is now set-up and configured to work with Heroku. You have a new Strapi project and a new Heroku app ready to be configured to work with a database and with each other.
# 7. Heroku Database set-up
Below you will find database options, when working with Heroku. Please choose the correct database (e.g. PostgreSQL) and follow those instructions.
# 8. Commit your changes
Path: ./my-project/
git add .
git commit -m "Update database config"
# 9. Update Yarn lockfile
Path: ./my-project/
yarn install
# 10. Commit your changes
Path: ./my-project/
git add yarn.lock
git commit -m "Updated Yarn lockfile"
# 11. Deploy
Path: ./my-project/
git push heroku HEAD:main
The deployment may take a few minutes. At the end, logs will display the url of your project (e.g. https://mighty-taiga-80884.herokuapp.com
). You can also open your project using the command line:
Path: ./my-project/
heroku open
If you see the Strapi Welcome page, you have correctly set-up, configured and deployed your Strapi project on Heroku. You will now need to set-up your admin user
as the production database is brand-new (and empty).
You can now continue with the Quick Start Guide, if you have any questions on how to proceed.
✋ CAUTION
For security reasons, the Content-type Builder plugin is disabled in production. To update content structure, please make your changes locally and deploy again.
# Project updates
When Strapi is deployed to Heroku, Heroku sets the environment variable to NODE_ENV=production
. In production mode
Strapi disables the content-type builder (for security reasons). Additionally, if you wanted to change the default production mode in Heroku, it wouldn't work as the file system is temporary. Strapi writes files to the server when you update the content-types and these updates would disappear when Heroku restarts the server.
Therefore, modifications that require writing to model creation or other json files, e.g. creating or changing content-types, require that you make those changes on your dev environment and then push the changes to Heroku.
As you continue developing your application with Strapi, you may want to use version control (opens new window), or you can continue to use git push heroku HEAD:main
to commit and push changes to Heroku directly.
Path: ./my-project/
git add .
git commit -am "Changes to my-project noted"
git push heroku HEAD:main
heroku open
# File Uploads
Like with project updates on Heroku, the file system doesn't support local uploading of files as they will be wiped when Heroku "cycles" the dyno. This type of file system is called ephemeral (opens new window), which means the file system only lasts until the dyno is restarted (with Heroku this happens any time you redeploy or during their regular restart which can happen every few hours or every day).
Due to Heroku's filesystem you will need to use an upload provider such as AWS S3, Cloudinary, or Rackspace. You can view the documentation for installing providers here and you can see a list of providers from both Strapi and the community on npmjs.com (opens new window).
# Gzip
As of version 3.2.1
, Strapi uses koa-compress
(opens new window) v5, which enables Brotli (opens new window) compression by default. At the time of writing, the default configuration for Brotli results in poor performance, causing very slow response times and potentially response timeouts. If you plan on enabling the gzip middleware, it is recommended that you disable Brotli or define better configuration params.
To disable Brotli, provide the following configuration in config/middleware.js
.
gzip: {
enabled: true,
options: {
br: false
}
},
For more on Brotli configuration for koa-compress
, reference this issue (opens new window).