How to Deploy Vapor Apps to Heroku
Time to read: 2 minutes
Building web applications with Swift using Vapor is super simple. Thankfully, deploying them is also a breeze. In just a few steps we’ll go from localhost to Heroku with Vapor’s CLI.
Prerequisites
We need a few things before we get started:
- A working Vapor web application. If you don’t have one, you can follow this tutorial to get started.
- Git
- A free Heroku account
- Heroku Command Line Interface – Make sure to run
heroku login
once the CLI is installed to authenticate your account.
Deploying to Heroku
Vapor supports deployment to any server that can run Swift. The Vapor CLI tool makes deployment to Heroku super simple.
If your Vapor app is not already in a Git repository we’ll need to add one. Run the following commands from your project directory:
Now that we have a Git repo we can use Vapor’s CLI to deploy our app to Heroku. Run this command to start the process:
Here’s how to answer the questions the CLI asks you:
- Choose whether you want to give your app a custom name on Heroku. This one’s up to you.
- Answer
n
to the custom executable name if you have not modified Vapor’s defaults ory
if you have. Answern
if you followed the previously mentioned tutorial. - Answer
y
to deploy now.
Grab some coffee because this will take 5-10 minutes. The reason it takes so long is Swift will be installed on your Heroku instance using swiftenv before building your app.
Once the process is done launch your browser to the Heroku URL provided by the output you should see your app running in the cloud. Here’s some sample output from the tutorial app mentioned above:
If you need to push new changes up to Heroku just commit those changes using
git
and then use Vapor CLI to push the new code:
That’s all there is to deploying Vapor apps to Heroku!
What’s Next?
Now that you’ve written some Vapor apps and deployed them to the cloud, what are you going to do next? Here’s some things you might consider:
- Check out the newly formed Swift Server APIs project
- Learn how to authenticate users in Vapor apps
- Try another Swift web framework such as IBM’s Kitura
No matter what you choose to do next, I’d love to hear about it. You can find me on Twitter @brentschooley or send me an email at brent@twilio.com.
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.