2

这是我将 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
4

2 回答 2

3

您是否遵循了每一个步骤?

cap deploy:setup

cap deploy:cold

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

我的部署.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
于 2013-10-14T14:57:23.890 回答
0

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

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

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

rvm use 1.9.3
passenger-config --ruby-command

然后使用命令的输出并将这一行添加到您的VirtualHost块中,以强制您的应用程序使用特定版本的 ruby​​。

PassengerRuby /path/to/ruby/1.9.3/

注意:这是PassengerDefaultRuby您已经定义的补充。(参见PassengerRuby的文档)

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

passenger-config --root

激活记录和调试以查看乘客到底在做什么

于 2013-10-16T05:28:20.387 回答