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)?
preg_match('|postgres://([a-z0-9]*):([a-z0-9]*)@([^:]*):([0-9]*)/(.*)|i', getenv('DATABASE_URL'), $matches); $user = $matches; $password = $matches; $server = $matches; $port = $matches; $database = $matches; return [ 'driver' => "pgsql", 'server' => $server, 'user' => $user, 'password' => $password, 'database' => $database, 'schema' => getenv('DB_SCHEMA'), 'tablePrefix' => getenv('DB_TABLE_PREFIX'), 'port' => $port ];
Procfile for Heroku:
web: vendor/bin/heroku-php-apache2 web/
# The environment Craft is currently running in ('dev', 'staging', 'production', etc.) ENVIRONMENT="dev" # The secure key Craft will use for hashing and encrypting data SECURITY_KEY="" # The database driver that will be used ('mysql' or 'pgsql') DB_DRIVER="pgsql" # The database server name or IP address (usually this is 'localhost' or '127.0.0.1') DB_SERVER="localhost" # The database username to connect with DB_USER="atc" # The database password to connect with DB_PASSWORD="" # The name of the database to select DB_DATABASE="blogdb" # The database schema that will be used (PostgreSQL only) DB_SCHEMA="public" # The prefix that should be added to generated table names (only necessary if multiple things are sharing the same database) DB_TABLE_PREFIX="" # The port to connect to the database with. Will default to 5432 for PostgreSQL and 3306 for MySQL. DB_PORT="5432" DATABASE_URL="postgres://atc:@localhost:5432/blogdb" DEFAULT_SITE_URL="https://landing-page.dev"
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
SECURITY_KEYin Config Vars of the Settings dashboard in Heroku). How getting a HTTP 503 "Service Unavailable" error when navigating to the remote server :(