---
title: "在heroku上部署sinatra应用"
author: "bellstar"
date: "2014-01-08T12:28:49Z"
tags: []
categories: ["编程语言"]
slug: "heroku-sinatra"
draft: false
lastmod: "2014-01-08T12:29:35Z"
id: 2001257
url: "https://bellstar.iteye.com/blog/2001257"
---

本文假定你已经拥有了heroku账号和成功安装heroku toolbelt。如果你还没有这么做，可以看这里[https://devcenter.heroku.com/articles/quickstart](https://devcenter.heroku.com/articles/quickstart)

01. 在[https://dashboard.heroku.com/apps](https://dashboard.heroku.com/apps)页面中选择Create a new app[]()
02. 输入app的名字，完成创建
03. clone项目git clone `git@heroku.com:appname.git` -o heroku
04. 创建Gemfile
    
    ```
    
    source "https://rubygems.org"
    ruby "1.9.3"
    gem 'sinatra', '1.4.4'
    
    ```
05. 创建web.rb作为web服务启动文件
    
    ```
    
    require "sinatra"
    
    get "/:name.html" do
      erb params[:name].to_sym
    end
    
    ```
06. 创建Procfile，foreman这个gem要用它作为配置，heroku通过foreman启动web服务
    
    ```
    web: bundle exec ruby web.rb -p $PORT
    ```
07. 创建app需要的其他文件
08. 添加文件到git中：git add . -m "add all"
09. 登录heroku：heroku login
10. 发布git push heroku master