gpt4 book ai didi

ruby-on-rails-3 - 在服务器上运行我的 Rails 应用程序

转载 作者:行者123 更新时间:2023-12-04 04:38:32 25 4
gpt4 key购买 nike

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

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

为此,我使用了 phusion 乘客和 apache。有遇到过类似情况的 friend 请帮帮我。任何帮助将不胜感激。提前致谢 :)

我尝试运行的服务器也有在 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

最佳答案

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

cap deploy:setup

cap deploy:cold

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

我的部署.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

关于ruby-on-rails-3 - 在服务器上运行我的 Rails 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19288853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com