Deploy
Here are the steps to deploy your application to Heroku, a popular cloud platform service that enables developers to build, run, and operate applications entirely in the cloud.
Last updated
Here are the steps to deploy your application to Heroku, a popular cloud platform service that enables developers to build, run, and operate applications entirely in the cloud.
Last updated
Even though this guide is specific to deploying to Heroku, you can choose any other provider you prefer. Fortunately, there are quite a few options out there. Through customer feedback, Heroku has proven to be amongst the easiest to setup (especially for beginners).
Firstly, go to https://heroku.com/ and create an account.
Run the following command to create a new app within Heroku, where my-app-name
is the unique name for your app:
In Heroku's dashboard, under your app's settings, use 'Reveal config vars' to add your production environment variables. These are key-value pairs that your application will use in production.
In order for your app to run smoothly, you'll need to include at least the following variables:
SECRET_KEY
here are a few different ways of generating a secure random secret key
ALLOWED_HOSTS
configure this setting as needed following the django guide: https://docs.djangoproject.com/en/5.0/ref/settings/#allowed-hosts
CSRF_TRUSTED_ORIGINS
configure this setting as needed following the django guide: https://docs.djangoproject.com/en/5.0/ref/settings/#csrf-trusted-origins
DEFAULT_FROM_EMAIL
and DEFAULT_FROM_NAME
there are used when sending emails to format your email sender name nicely.
In order to have workers running you need to setup Redis, which provides an in-memory data structure store, used as a database, cache, and message broker.
Run the following command to add the Redis addon to your Heroku app
Remember to replace my-app-name
with the name you used in step 1
Like for the local setup, you'll need to create a Postgres database for your app to run as expected.
Heroku Postgres is a managed SQL database service provided by Heroku.
To create a Postgres database in Heroku run the following command:
make sure you chose your desired database size before running the command. The sample command below, specifies the basic tier. You can see the list Heroku Postgres database tiers here.
Heroku offers a variety of options for how to deploy your app.
If you choose to use Github to store your code, then the Github deployment method will be the most convenient for you.
Alternatively, you can deploy your app manually using the following Heroku CLI command:
Take a look at the Procfile within the Ready SaaS repo. This file specifies the commands that are executed by the app on startup (on each deployment). Docs about the Heroku Procfile
This command runs Django's createsuperuser management command on Heroku, allowing you to create an admin user to access the Django admin dashboard.
Now you can navigate to your app's url, and add /admin
to the url path to access your admin dashboard.
You can get your Heroku App's url by clicking this button:
Within your admin dashboard, make sure to create all the necessary objects required to run your app. If you're running the project "as is", make sure to create subscription plans for the landing page to load without errors.
For your background tasks to work in your production Heroku app, you need to spin up a Heroku Dyno for the worker and for the celery beat. These commands scale up your worker and Celery beat dynos to ensure that background tasks and periodic tasks are handled properly in your production environment:
What's great about Heroku Dynos is that you can scale to any amount needed by your site.