Deploy your app to Heroku
In this tutorial, you'll learn how to apply the instructions to deploy an app to Heroku.
Requirements
Anchor link to section titled "Requirements"You've created an app using Shopify CLI, or you've migrated your app to work with Shopify CLI.
You have a Heroku account and can create apps on it.
Step 1: Create an app configuration file
Anchor link to section titled "Step 1: Create an app configuration file"Create or link your app to an app.toml
file. We recommend that developers have one configuration for development, and a separate one for production. That way, you can continue to develop your app after deploying it, without affecting your production environment.
Either create a new configuration, or use an existing one:
Get the necessary environment variables to deploy your app:
Note down the
SHOPIFY_API_KEY
,SHOPIFY_API_SECRET
, andSCOPES
values. You'll need to set them as environment variables before you can run your deployed app.
Step 2: Create and configure your Heroku app
Anchor link to section titled "Step 2: Create and configure your Heroku app"Create a new Heroku app using the Heroku CLI.
- Download and install the Heroku CLI.
Log in to the Heroku CLI:
Log in to the Heroku Container Registry:
Create an app in Heroku:
This command configures Heroku with a container-based app and creates a Git remote branch named
heroku
for deploying the app. It also returns the URL where the app will run when it's deployed.
Create a Heroku config file
Anchor link to section titled "Create a Heroku config file"To deploy the app, you'll need to add a Heroku configuration file to tell Heroku how to build the app.
At the top-level directory of your app's source code, create a
heroku.yml
file with the following content:Commit the
heroku.yml
file to your Git repository:
Step 3: Configure your app
Anchor link to section titled "Step 3: Configure your app"Configure your Heroku app to run your app code and communicate with Shopify.
Prepare database
Anchor link to section titled "Prepare database"Create a container running your preferred database, then make sure your Prisma schema file points to it.
For databases such as PostgreSQL or MySQL, you can use the DATABASE_URL
environment variable in your schema to point to your container in different environments.
Refer to these important considerations for setting up your database.
Set environment variables
Anchor link to section titled "Set environment variables"You'll need to set the following environment variables for your app:
In a terminal, add the environment variables for your app using the
heroku config:set
command. You'll need your app's URL, so visit your Heroku dashboard and copy your app's URL.With the URL, and the values from the
shopify app env show
command you ran before, run this command:
Step 4: Deploy your configuration
Anchor link to section titled "Step 4: Deploy your configuration"Before running the app on your hosting provider, you'll need to update your Shopify settings by deploying your TOML file using Shopify CLI.
In the
shopify.app.*.toml
file for your deployment environment, setapplication_url
to the same as theSHOPIFY_APP_URL
environment variable:Deploy your configuration to apply the changes to Shopify:
Step 5: Deploy your Heroku app
Anchor link to section titled "Step 5: Deploy your Heroku app"Your app is ready to deploy now. You can do that following these steps:
Push the app to Heroku. It will automatically build the
docker
image and deploy the app whenever you push to theheroku
remote:Visit your Heroku dashboard, and check your logs to verify that the app started as expected.
Step 6: Test your deployed app
Anchor link to section titled "Step 6: Test your deployed app"After you update your app URLs in the Partner Dashboard, you can test your app in a development store to make sure that it's configured correctly.
- In the Partner Dashboard, go to your app's Overview page.
- In the Test your app section, click Select store and choose a store to test the app.
Re-deploying your app
Anchor link to section titled "Re-deploying your app"As you continue developing your app, you can re-deploy it with the following steps:
Select your production app with Shopify CLI:
Deploy your app configuration and extensions, if you made any changes:
Trigger a new deploy in Heroku: