在服务器上运行我的rails应用程序

时间:2013-10-10 06:45:13

标签: ruby-on-rails-3 apache passenger

这是我第一次将rails应用程序部署到服务器。它在本地工作得非常好,但是当我试图将它移动到服务器进行生产时,它并没有显示出来。我得到的只是显示我的项目文件夹的图像。我需要做出任何改变吗?

以下是我已经完成的更改 - database.yml - >生产 改变了环境

我为此目的使用过phusion乘客和apache。任何遇到类似情况的人,请帮帮我。任何帮助将受到高度赞赏。在此先感谢:)

我尝试运行的服务器还有在ruby 1.8.7上运行的项目;当我的项目使用另一个项目的gemsets时有2个实例。所以不得不使用.rvmrc(我知道现在已弃用)将它指向我应用应该使用的正确gemset。

配置:

<VirtualHost *:80>
  ServerName cloudapp.net
  DocumentRoot /var/www/test1/public
  <Directory /var/www/test1/public>
    Allow from all
    Options -MultiViews
  </Directory>
</VirtualHost>

乘客配置:

LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.20/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.20
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-1.9.3-p448/ruby

2 个答案:

答案 0 :(得分:3)

您是否遵循了每一步?

cap deploy:setup

cap deploy:cold

你创建了符号链接吗?我将在这里发布我的文件的工作演示..

我的deploy.rb

require 'capistrano/ext/multistage'
require "bundler/capistrano"
require "rvm/capistrano"

set :user, 'ubuntu'
set :application, "yourapp"
set :use_sudo, true

$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
set :rvm_path,          "/home/ubuntu/.rvm"
set :rvm_bin_path,      "#{rvm_path}/bin"
set :rvm_lib_path,      "#{rvm_path}/lib"


set :rvm_ruby_string, 'ruby-1.9.3-p448'
set :rvm_type, :system

set :default_environment, {
  'PATH' => "/home/ubuntu/.rvm/gems/ruby-1.9.3-p448/bin:/home/ubuntu/.rvm/gems/ruby-1.9.3-p448@global/bin:$PATH",
  'RUBY_VERSION' => 'ruby-1.9.3-p448',
  'GEM_HOME'     => "/home/ubuntu/.rvm/gems/ruby-1.9.3-p448",
  'GEM_PATH'     => "/home/ubuntu/.rvm/gems/ruby-1.9.3-p448:/home/ubuntu/.rvm/gems/ruby-1.9.3-p448@global",
  'BUNDLE_PATH'  => "/home/ubuntu/.rvm/gems/ruby-1.9.3-p448:/home/ubuntu/.rvm/gems/ruby-1.9.3-p448@global"  # If you are using bundler.
}


set :scm, 'git'
# # repository to be set for gitlab
set :repository, "git@github.com:ur-repo.git"


# set :branch, "staging"


set :git_shallow_clone, 1
set :deloy_via, :remote_cache
set :keep_releases, 3
set :scm_verbose, true


set :stages, ["staging", "production"]
set :default_stage, "staging"

set :migrate_target, :latest



default_run_options[:pty] = true
ssh_options[:forward_agent] = false
ssh_options[:keys] = ["yourfile.pem"]



after "deploy:create_symlink", "deploy:bundle_install"

namespace :bundler do
  task :create_symlink, roles: :app do
    shared_dir = File.join(shared_path, 'bundle')
    release_dir = File.join(current_release, '.bundle')
    run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
  end

  task :bundle_new_release, roles: :app do
    bundler.create_symlink
    run "cd #{release_path} && source $HOME/.bash_profile && bundle install"
  end
end

after 'deploy:finalize_update', 'bundler:bundle_new_release'
after 'deploy:bundle_install', 'deploy:precompile_application'
after 'deploy:restart', 'deploy:cleanup'

我的staging.rb

set :domain, "yourdomain"


set :rails_env, "staging"

# roles (servers)
role :web, domain
role :app, domain
role :db,  domain, :primary => true


set :deploy_to, "/var/www/#{application}"



namespace :deploy do

  desc "Copy config files"
  after "deploy:update_code" do
    run "export RAILS_ENV=staging"
    run "cp #{shared_path}/config/database.yml #{release_path}/config/"
    run "cp #{shared_path}/config/environments/staging.rb #{release_path}/config/environments/"
    run "mkdir -p #{release_path}/public/images/ProfilePics"    
    sudo "chmod -R 0777 #{release_path}/tmp/"
    sudo "chmod -R 0777 #{release_path}/log/"
  end

  task :restart, roles: :app, except: { no_release: true } do
    run "touch #{File.join(current_path,'tmp','restart.txt')}"
  end

  desc 'run bundle install'
  task :bundle_install, roles: :app do
    run "cd #{current_path} && bundle install --deployment --path #{shared_path}/bundle"
  end  

  desc "Reset the database"
  task :reset do
    # on_rollback { deploy.db.restore }
    run "cd #{current_path}; bundle exec rake db:reset RAILS_ENV=staging"
  end

  desc "Migrate the database"
  task :migrate do
    # on_rollback { deploy.db.restore }
    run "cd #{current_path}; bundle exec rake db:migrate RAILS_ENV=staging"
  end

  task :seed do
    run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=staging"
  end


  task :precompile_application do
    run "cd #{current_path}; bundle exec rake assets:precompile RAILS_ENV=staging"
  end

end

答案 1 :(得分:0)

您的乘客配置看起来不错。

您的PassengerDefaultRuby指向1.9.3-p448。是什么让你相信它正在使用1.9.3-p225

由于您使用RVM,请运行这些命令为您的乘客找到正确的红宝石路径

rvm use 1.9.3
passenger-config --ruby-command

然后使用命令的输出并在VirtualHost块中添加此行以强制您的应用程序使用特定版本的ruby。

PassengerRuby /path/to/ruby/1.9.3/

注意:这是您已定义的PassengerDefaultRuby的补充。 (See Documentation for PassengerRuby)

运行此命令以检查文件夹权限

passenger-config --root

激活Logging and Debugging以了解乘客究竟在做什么