这是我第一次将Rails应用程序部署到服务器上的经验。它在本地工作得很好,但是当我尝试将其移动到服务器进行生产时,它没有显示。我所得到的只是显示的项目文件夹的图像。我需要进行任何更改吗?
以下是我已经完成的更改-database.yml->生产更改了环境
我为此目的使用了phusion乘客和apache。遇到过类似情况的任何人,请帮助我。任何帮助将不胜感激。提前致谢 :)
我尝试运行的服务器上也有在ruby 1.8.7上运行的项目。当我的项目使用另一个项目的gemset时,有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
您是否遵循了每个步骤?
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, "[email protected]: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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句