I'm relatively new to Craft 3, and am able to run Craft locally with a Postgres db and Valet as my server. When I try to deploy to Heroku, I run into issues with (I think) Postgres.


I tried setting up Craft to work with Heroku by following this guide (see the "Publishing" section near the bottom of the guide). I found that if I just run a heroku create and then push my local branch to the remote server, I get an "Internal Server Error" when loading the remote site on Heroku.

Instead, I created an app.json file as per this guide by @edenspiekermann. Then I run https://heroku.com/deploy with arguments to create the Heroku app, and this allows me to access the Craft admin page at /admin/install on the remote server.

Following the first guide, I also push my local Postgres database to Heroku with heroku pg:push DB_NAME DATABASE_URL --app HEROKU_APP_NAME.


-How does Heroku know the right DATABASE_URL to use in /config/db.php? Locally, that variables comes from .env which is not pushed to my repo or Heroku.

-Why does Heroku show an internal server error if I just push my local branch to the remote server (whereas creating a Heroku app with https://heroku.com/deploy works)?

My db.php file:

preg_match('|postgres://([a-z0-9]*):([a-z0-9]*)@([^:]*):([0-9]*)/(.*)|i', getenv('DATABASE_URL'), $matches);

$user = $matches[1];
$password = $matches[2];
$server = $matches[3];
$port = $matches[4];
$database = $matches[5];

return [
  'driver' => "pgsql",
  'server' => $server,
  'user' => $user,
  'password' => $password,
  'database' => $database,
  'schema' => getenv('DB_SCHEMA'),
  'tablePrefix' => getenv('DB_TABLE_PREFIX'),
  'port' => $port

My Procfile for Heroku:

web: vendor/bin/heroku-php-apache2 web/

My .env file:

# The environment Craft is currently running in ('dev', 'staging', 'production', etc.)

# The secure key Craft will use for hashing and encrypting data

# The database driver that will be used ('mysql' or 'pgsql')

# The database server name or IP address (usually this is 'localhost' or '')

# The database username to connect with

# The database password to connect with

# The name of the database to select

# The database schema that will be used (PostgreSQL only)

# The prefix that should be added to generated table names (only necessary if multiple things are sharing the same database)

# The port to connect to the database with. Will default to 5432 for PostgreSQL and 3306 for MySQL.



Error I receive when navigating to homepage on Heroku after I've pushed my local Postgres db to Heroku remote:

HTTP 503 – Service Unavailable – craft\web\ServiceUnavailableHttpException
  • Was able to figure out the answer to my two questions (by setting the ENVIRONMENT and SECURITY_KEY in Config Vars of the Settings dashboard in Heroku). How getting a HTTP 503 "Service Unavailable" error when navigating to the remote server :(
    – atc
    Sep 24, 2019 at 0:51

2 Answers 2


Found out that there are a variety of Config vars in Heroku you need to set that match your local .env file. In particular:


Edit 10.1.19 Wrote this tutorial on how to get Craft 3 up and running on Heroku.


Craft/Yii on Heroku has been made much simpler with the addition of the url config option:

<?php return [
    // ...
    'production' => [
        'url' => getenv('DATABASE_URL')
    // ...

I think there are too many factors for us to say why the one-click deploy works, but pushing an existing application doesn't—it could be that one of the custom environment variables isn't populated (as it would be with Heroku's deploy/app wizard).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.