6 Tips for Deploying Strapi to Heroku

Strapi is a great headless CMS for front-end developers. It’s open-source, flexible, and easy to set up. After endless frustration with headless Wordpress, using Strapi was a breath of fresh air.

Getting set up was easy. Deploying was confusing. I like Heroku because it can host my side-projects for free. However, deploying Strapi to Heroku presented some unique challenges. Here’s what you need to know.

1. Don’t spend too much time adding content locally

Data migration between environments is currently in the planning phase on Strapi’s roadmap. For now, I had to re-add my data.

Know this from the off. If you have lots of content, save it for when you’ve deployed.

2. You will need a database, and it can’t be SQLite

Heroku doesn’t support SQLite but it’s surprisingly quick to set one up with Postgres by installing a Heroku Add-On. The instructions can be found in this tutorial.

3. Some Tutorials are Out of Date

./config/environments/production/database.json

After finding the same non-existent path here, here and here, I thought I had skipped a step during set-up.

If this happens to you, use this tutorial. This has the Heroku deployment guide for the current version, not the beta.

Strapi is evolving rapidly, which means some tutorials are out-of-date despite being barely a year old. At the time of writing, the current version is less than a month old. It’s only a matter of time before tutorials get updated or replaced.

4. You will need Cloudinary or AWS S3 to host your images

In Strapi’s own words:

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, 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).

To get around this, we can use Cloudinary to host our images. This means we can still upload images via the Strapi admin panel, but the images get saved on Cloudinary’s servers instead of Heroku’s. When fetching an image on your front-end, Strapi will return a Cloudinary URL instead of a file path.

Cloudinary has a free tier; it can perform image optimization, and deliver images in WebP format. This makes it a great tool to improve your website’s performance.

5. You don’t need to do anything in the Strapi admin panel after configuring Cloudinary

This step is no longer required.

Settings are now defined in extensions/upload/config/settings.js, not inside the Strapi admin panel. This means once you have pushed settings.js to Heroku, you’re all set.

6. Don’t forget to set-up your config vars!

Sensitive information like API keys should not be pushed to Heroku or Github with the rest of your project. If you’ve installed and configured Cloudinary but can’t upload images, check the Config Vars in your Heroku settings.

The Config Vars section of the Heroku dashboard is where you can securely store sensitive variables. This set is required for using Postgres and Cloudinary

Resources

Strapi’s guide to Heroku deployment (current version):

YouTube tutorial series. The videos on deployment reference an older version of Strapi. The series overall is still extremely worthwhile:

Full-stack developer and Django enthusiast. When I can’t find Django tutorials, I write them. https://twitter.com/alcampk

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store