在heroku上部署ruby on rails 开发的网站 Ubuntu

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/while10/article/details/79053563

首先讲一下,你要在heroku上注册一个账号注册网址,但是需要翻墙,如果不翻墙,验证码刷新不出来,注册的时候最好使用gmail账号,我用的outlook的邮箱注册的也可以。
我讲的这个部署过程需要拥有ubuntu系统(linux),在ubuntu上已经有一个开发好的ruby网站,对这个网站进行部署到heroku云。
与git的关系:git是一个版本管理工具,但是必须安装Heroku的Heroku Toolbelt,它里面自带了git,与heroku建立了某种关系,使得git push heroku可以直接把项目发到远程的heroku服务器的某个你建立项目的地方。
**git发送项目的要求:**git发送的东西必须能够让heroku知道这是个什么项目,如何安装,运行等。 当然有些可以通过 heroku run “your commond” 命令自行配置。

思路整理:heroku先创建项目,给你留个位置,git发送你的项目到那个地方,heroku根据配置文件,自动判断帮你运行。
**

1.修改数据库

**
heroku使用的是PostgreSql而不是sqlite3,因此需要修改Gemfile以后才可以到heroku上运行。修改Gemfile中的:

gem 'sqlite3'

将它改为

group :development do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
end

这样在开发环境中使用Sqlite3,在部署上线后使用PostgreSql.

2.加载库

bundle install --without production

3.登录heroku

heroku login

会提示输入email和password(就是之前注册的),登录成功后新建app:

heroku create --myappname

–后面的名字可以起你自己想的名字

4.push代码

把代码加入到git版本库:

git init
git add .
git commit -m "first commit"

push到heroku:

git push heroku master

可以看到以下输出:

remote: ###### WARNING:
remote:        No Procfile detected, using the default web server (webrick)
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server
remote: 
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console, rake, web, worker
remote: 
remote: -----> Compressing... done, 28.5MB
remote: -----> Launching... done, v7
remote:        https://tuishu.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy.... done.
To https://git.heroku.com/tuishu.git
   2f25861..959154c  master -> master

当看到Verifying deploy…. done.的时候说明push完毕。

5.迁移数据库

heroku run rake db:migrate
heroku run rake db:seed

6.访问app

heroku open

7.这个命令(相关的命令,可以不看)

远程连接:

heroku git:remote -a tuishu

远程clone

heroku git:clone -a tuishu

*Heroku部署完成!*

8. 以后每次部署新功能时

$ git pull

$ git push heroku master

重置数据库,seed数据只能这样更新

$ heroku run rake db:reset

猜你喜欢

转载自blog.csdn.net/while10/article/details/79053563