问题描述
这是我部署一个Rails应用程序到服务器第一次经历。它的工作原理完全没有在本地,但是当我试图把它移动到服务器进行生产,它不会显示出来。我得到的是我的显示项目文件夹的影像。我是否需要做任何改变?
以下是我已经做了改变 -
database.yml的 - >生产
改变环境
我用的Phusion乘客和Apache用于这一目的。任何人谁也面临类似的情况,请帮助我。任何帮助将是非常美联社preciated。在此先感谢:)
另外我想上运行有红宝石1.8.7运行项目的服务器;有我的项目用另一个项目的gemsets时2实例。所以只好用.rvmrc(这是我所知道的是pcated截至目前德$ P $),将它指向我的应用程序应该使用合适的宝石。
配置:
<虚拟主机*:80>
服务器名cloudapp.net
的DocumentRoot的/ var / WWW / TEST1 /公
<目录/ var / WWW / test1的/公共及GT;
所有允许
选项-MultiViews
< /目录>
< /虚拟主机>
乘客配置:
的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
你有没有跟着每一个步骤?
上限部署:安装帽部署:冷
你有没有创建符号链接?我将发布我的文件的工作演示在这里..
我deploy.rb
要求'Capistrano的/转/多级
要求打捆/ Capistrano的
要求RVM / Capistrano的集:用户,Ubuntu的
设置:应用程序,yourapp
设置:use_sudo,真$ :.不印字(File.expand_path('./库',ENV ['rvm_path']))
设置:rvm_path,/home/ubuntu/.rvm
设置:rvm_bin_path,#{} rvm_path / BIN
设置:rvm_lib_path,#{} rvm_path / lib目录
集:rvm_ruby_string,'红宝石1.9.3-P448
设置:rvm_type,:系统设置:default_environment,{
路径= GT; \"/home/ubuntu/.rvm/gems/ruby-1.9.3-p448/bin:/home/ubuntu/.rvm/gems/ruby-1.9.3-p448@global/bin:$PATH\",
RUBY_VERSION'=> 红宝石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#如果你使用的是打捆。
}
设置:SCM,混帐
##库为gitlab设置
设置:仓库,git@github.com:UR-repo.git
#集:分支,分期
集:git_shallow_clone,1
设置:deloy_via,:remote_cache
设置:keep_releases,3
集:scm_verbose,真
设置:阶段,[分期,生产]
设置:default_stage,分期设置:migrate_target,:最新default_run_options [:PTY] =真
ssh_options [:forward_agent] = FALSE
ssh_options [:键] = [yourfile.pem]后部署:create_symlink,部署:bundle_install命名空间:打捆做
任务:create_symlink,角色:应用程序做
shared_dir = File.join(shared_path,'捆绑')
release_dir = File.join(current_release,'.bundle)
运行(命令mkdir -p#{shared_dir}&放大器;&安培; LN -s#{shared_dir}#{release_dir})
结束 任务:bundle_new_release,角色:应用程序做
bundler.create_symlink
运行CD#{release_path}&放大器;&安培;源$ HOME / .bash_profile中和放大器;&安培;捆绑安装
结束
结束后部署:finalize_update','打捆:bundle_new_release
后部署:bundle_install','部署:precompile_application
后部署:重启,部署:清除
和我staging.rb
设置:域,YOURDOMAIN
设置:RAILS_ENV,分期#角色(服务器)
作用:网络,域名
角色:应用程序,域名
作用:DB,域:初级=>真正
设置:deploy_to,/无功/网络/#{}应用命名空间:部署做 递减复制配置文件
后部署:update_ code做
运行出口RAILS_ENV =分期
运行CP#{} shared_path#/config/database.yml {} release_path /配置/
运行CP#{} shared_path#/config/environments/staging.rb {} release_path /配置/环境/
运行命令mkdir -p#{} release_path /公关/图像/ ProfilePics
须藤搭配chmod -R 0777#{} release_path的/ tmp /
须藤搭配chmod -R 0777#{} release_path /日志/
结束 任务:重启,角色:应用程序,除了:{no_release:真正做}
运行触#{File.join(的current_path,'tmp目录','restart.txt')}
结束 说明运行包安装
任务:bundle_install,角色:应用程序做
运行CD#{}的current_path功放及;&安培;捆绑安装--deployment --path#{} shared_path /捆
结束 DESC重置数据库
任务:复位时,
#on_rollback {} deploy.db.restore
运行CD#{}的current_path;捆绑的exec耙分贝:重置RAILS_ENV =分期
结束 DESC迁移数据库
任务:迁移做
#on_rollback {} deploy.db.restore
运行CD#{}的current_path;捆绑的exec耙分贝:迁移RAILS_ENV =分期
结束 任务:做种子
运行CD#{}的current_path;捆绑的exec耙分贝:种子RAILS_ENV =分期
结束
任务:precompile_application做
运行CD#{}的current_path;捆绑的exec耙资产:precompile RAILS_ENV =分期
结束结束
This is my first experience deploying a rails app to a server. It works perfectly fine locally, but when I am trying to move it to the server for production, it doesn't show up. All I get is my project folder's images shown. Do I need to make any changes?
Following are the changes I have already done -database.yml -> productionchanged the environment
I have used phusion passenger and apache for this purpose. Anyone who has faced a similar situation, please help me out. Any help will be highly appreciated. Thanks in advance :)
Also the server I am trying to run on has projects running on ruby 1.8.7; there were 2 instances when my project was using another project's gemsets. So had to use .rvmrc (which i know is deprecated as of now) to point it to the right gemset that my app should be using.
Configuration:
<VirtualHost *:80>
ServerName cloudapp.net
DocumentRoot /var/www/test1/public
<Directory /var/www/test1/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Passenger Configuration:
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
Have you followed every steps?
cap deploy:setup
cap deploy:cold
Have you created symlinks? I will post a working demo of my file here..
My 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'
And my 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
这篇关于运行在服务器上我的Rails应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!