{"title":"Heroku","description":"","section":"deployment","version":"v1.5","path":"deployment/heroku","canonical_url":"https://amberframework.org/docs/v1.5/deployment/heroku","markdown_url":"https://amberframework.org/docs/v1.5/deployment/heroku.md","inherited":true,"content_markdown":"# Heroku\n\n{% hint style=\"danger\" %}\nAmber `0.7.2` isn't compatible with Crystal `0.25.0`\n\nPlease use a `.crystal-version` file with `0.24.2` instead\n{% endhint %}\n\nIf you haven't done so please read the guides to install the [Amber CLI](https://github.com/amberframework/docs/tree/5444592f267091cce244d8f7436cb56454605510/getting-started/installation/heroku.md)\n\n## The Amber Heroku Buildpack\n\n{% hint style=\"info\" %}\nBased on [Crystal Heroku Buildpack](https://github.com/crystal-lang/heroku-buildpack-crystal)\n{% endhint %}\n\nYou can create an app in Heroku with Amber buildpack by running the following command:\n\n```bash\n$ heroku create myapp --buildpack https://github.com/amberframework/heroku-buildpack-amber.git\n$ heroku buildpacks:add --index 2 heroku/nodejs # To build default assets\n```\n\nThe default behaviour is to use the [latest crystal release](https://github.com/crystal-lang/crystal/releases/latest). If you need to use a specific version create a `.crystal-version` file in your application root directory with the version that should be used \\(e.g. `0.23.1`\\).\n\n## Requirements\n\nFirst of all you need to add Heroku addons: `Heroku Redis` and `Heroku Postgres` for created app. Then uncomment in `config/settings.cr`:\n```\nsettings.redis_url = ENV[\"REDIS_URL\"] if ENV[\"REDIS_URL\"]?\n\nsettings.database_url = ENV[\"DATABASE_URL\"] if ENV[\"DATABASE_URL\"]?\n```\n\nIn order for the buildpack to work properly you should have a `shard.yml` file,as it is how it will detect that your app is a Crystal app. Your application has to listen on a port defined by Heroku.\n\n{% hint style=\"warning\" %}\nIn Amber versions less than or equal to 0.3.7 add the following code to your `config/application.cr` file\n{% endhint %}\n\n```crystal\nAmber::Server.configure do |settings|\n  settings.host = \"0.0.0.0\"\n  settings.port = ENV[\"PORT\"].to_i if ENV[\"PORT\"]?\nend\n```\n\nTo be able to decrypt and use production environment you'll need to set `ENV[\"AMBER_ENCRYPTION_KEY\"]` to the value of your local projects `.encryption_key` file.\n\n{% hint style=\"danger\" %}\nNever add `.encryption_key` to github. Amber adds it by default to your `.gitignore` file.\n{% endhint %}\n\nAll that's left is to create a git repository, add the Heroku remote and push it there.\n\n```text\n$ git init\n$ heroku git:remote -a [app-name]\n$ git add -A\n$ git commit -m \"My first Amber app\"\n$ git push heroku master\n```\n\n## Using the Amber CLI on Heroku\n\nWhen you deploy your project to heroku the amber build-pack will make available the `amber cli` to you via the `bin/amber` path.\n\nTo run an amber command just on heroku do the following:\n\n```text\nheroku run bin/amber [command]\n```\n\n{% hint style=\"info\" %}\nRead more about `heroku run` command on [Heroku Dev Center](https://devcenter.heroku.com/articles/one-off-dynos)\n{% endhint %}\n\n## The Heroku Procfile\n\nTo deploy your app to heroku you're going to need a `Procfile`. Create a Procfile at the root of your Amber application and add the following:\n\n```yaml\nrelease: bin/amber db migrate\nweb: bin/{your-app-name}\n```\n\nThe Amber buildpack takes care of compiling the project for you but if you wish to run your project locally using the heroku command `heroku local` you must do the following steps.\n\nCreate an `.env` at the root of your Amber project and add the following 2 lines to the `.env`\n\n```text\nAMBER_ENV=development\nPORT=3000\n```\n\nThen you must compile your project locally with the following command:\n\n`crystal build src/{your-app-name}.cr -o bin/{your-app-name}`.\n\nWhen the compilation process is complete a `bin/{your-app-name}` directory is added, with this binary of your application with this binary file ready you can proceed to run your application locally with heroku.\n\n```text\nheroku local\n```\n\nAnd should output something similar to:\n\n```text\n[OKAY] Loaded ENV .env File as KEY=VALUE Format\n02:58:31 web.1   | 02:58:31 Server     | (INFO) Amber 0.7.2 serving application \"heroku-app\" at http://0.0.0.0:3000\n02:58:31 web.1   | 02:58:31 Server     | (INFO) Server started in production.\n02:58:31 web.1   | 02:58:31 Server     | (INFO) Startup Time 00:00:00.000182000\n```\n\nYou're are now all set and ready to deploy with Heroku."}