Deploy a Rails app on Dreamhost - ruby-on-rails

I am trying to deploy my first Rails app. I copied all files to ~/mysite.com and set up MySql.
Here's my configuration at Dreamhost.
Now when I visit mysite.com I get a 404 error (which isn't my custom 404 error). It seems that Passenger does not run!
What should I do? Do I need to start Passenger? (touch tmp/restart.txt does nothing)

Based on your stack trace at http://www.foto-fiori.com/ it looks like there's a gem missing on your production server. Check the gem list in your environment.rb config file and ensure all gems are installed. You can also ssh into your application and run rake gems.
rake gems RAILS_ENV=production
You may want to freeze the gems if Dreamhost does not allow you to install them.
rake rails:freeze:gems

4 things to check first:
You enabled Ruby on Rails Passenger (mod_rails) for the domain name
You point your domain name configuration to the public directory of your application.
Your Rails Version (As of 8/5/2009 Rails is up to 2.3.3 but Dreamhost is at 2.2.2)
All your gem dependencies are available at Dreamhost, in your home folder, or are unpacked in your rails application.
If passenger is giving you an error message then your rails app isn't starting, but passenger will put something in the apache logs.
These are in: ~/logs/domain.name/http/
Usually this is because of the wrong rails version or a missing gem or some other mismatch between the dreamhost environment and your development machine.

Related

Rails : Cannot include PgSearch Module provided by the pg_search Gem

TO SUM UP :
The module PgSearch provided by the Gem pg_search cannot be included, required or loaded on the staging environment (Rbenv, nginx, unicorn,capistrano), the problem happens on the web server through http but does not appear on the staging server's rails command.
An other module provided by an other gem can be included without error.
No problem on the local development environment (rvm, puma).
DETAILS
I am currently developing a Ruby On Rails 4.0 application with ruby 2.0.0 which git repositories are hosted on bitbucket.
I deploy the app through a staging server using capistrano.
Staging server environment : rbenv, nginx and unicorn
Local development environment : rvm and puma
The rails environnment files (environment/production.rb & environment/staging.rb) for both are the same.
WHAT DID I DO :
I have installed the pg_search gem (a PostgreSQL full text search gem) by adding it to my Gemfile and put the clause "include PgSearch" in the Active Record model I wanted to use with pg_search gem
I have run the app in development mode... it works !
PROBLEM :
After having deployed the changes to the staging server :
Through the http server I get this error :
NameError in App::MyController#index
Uninitialized constant MyActiveRecordModel::PgSearch
(Normally, this pg_search gem which is included in the GemFile should have its lib/*.rb files included in the autoload search path and a clause like load "pg_search.rb", require"pg_search" or "include PgSearch" (module included in pg_search.rb file) should pass.
In order to find clues to fix the bug, I have :
-tried if an other module provides by the gem could be included ... It works
After been to the current release path of the staging server I run "bundle exec rails c staging" and tried to :
see if the ActiveRecord Model ( which I included PgSearch) instanciation works.
see if the Module provided by the gem could be found / loaded on the server
and I have executed - include PgSearch and require "pg_search" and load "pg_search.rb".
All these commands were a succeess.
I run out of ideas to find some other clues, would you have any suggestions please ?
Thank you.
Restart the rails server
Gems introduce new code that rails will need to access. To make the new code available to Rails we go through 3 steps:
Change the Gemfile
bundle install
Restart the rails server
When do I need to restart the rails server?
It is easy to forget a step.

Can't access Rails console for app deployed on Passenger using Capistrano & RVM

After finally managing to get my Rails app working, I've got stuck with a slightly perplexing problem. I've deployed my Rails 3.0.5 app to a Ubuntu 10.10 server with Capistrano, RVM and Nginx. All is working nicely and I can confirm Rails is working as I'm getting data from the database and meaningful log messages.
The problem is that on the server, I can't access the console. When I try
rails c
It says "The program 'rails' is currently not installed. To run 'rails' please ask your administrator to install the package 'rails'"
However it is installed otherwise my application wouldn't work! I've only got two RVM gemsets installed, the global one and one called "rails305". Trying
rvm gemset use rails305
then
gem list
doesn't show any of the gems that my app needs, however they must be installed because 1) the app wouldn't work without them and 2) in my Capistrano deploy script, bundler installs them (to that gemset). So the problem is obviously something to do with RVM but I can't work out what it is... anyone any ideas?
It looks like Capistrano uses bundler so you might want to try
bundle exec rails c
from the deployment directory.
See the Bundler deployment page for more information.
Bundler by default doesn't install gems into the default rvm environment when deployed via capistrano, it installs to the "shared/bundle" directory instead, to try and accommodate production installation environments that aren't using RVM. If you are using RVM in production, and want to just have bundler install to your default ruby/gemset (which is terribly useful if you are going to be logging into the production, running rake scripts, console, etc), add the following options to your config/deploy.rb:
set :bundle_dir, ""
set :bundle_flags, ""
This will remove the "--deployment" (and "--quiet", which you may or may not want to keep) and --path flags which cause bundler to try and package everything up nicely, so bundler will now install to the user's RVM environment; making your server environment work a lot more like your dev environment (which can be good or bad depending on what your needs are).

Rails error 500 on local mac

Ok, I'm a noob with rails... so I just set up rails with RVM and created a new project, and when I try to visit a newly created view I'm getting an error 500.
Heres my setup:
OSX 10.6.5
Installed MySQL 64bit
RVM installed ruby 1.8.7 and rails 2.3.8 (no other rails or ruby except for the system ruby) rvm install 1.8.7, rvm use --create 1.8.7#rails2, gem install rails -v=2.3.8
Passenger with Apache gem install passenger, rvmsudo passenger-install-apache2-module
Passenger preference pane
Turned on websharing
I then proceeded to setup a rails project in my development folder called testapp, added it in the passenger preference pane, and then ran script/generate controller Say, defined an action hello, and then created a view in the app/view/say folder called hello.
Now I'm getting a 500 error when visiting myapp.local/say/hello, what am i doing wrong?
UPDATE:
I checked the logs and also tried running using WEBrick instead of passenger and apache. I got thrown back the same errors. I don't think I should post the entire log, should I? But the first error is
no such file to load -- sqlite3
I have not yet setup a db, I was going to use mysql, but I didn't want to install it since I'm not using models yet. Is it a requirement?
UPDATE 2:
So I installed the mysql gem with gem install mysql -- --include=/usr/local/lib (not sure if this is right). I then created a rails app with rails -d mysql myapp. And set the password in the database.yml. I'm getting a new error now:
Unknown database 'myapp_development'
So I have to create a database. Why am I being forced to create a db at all?
Yeah, you need to install sqlite even if you're not using models yet - Rails checks to make sure whatever is specified in database.yml is actually there to use.
Don't access it through passenger, launch it using ruby script/server and check out the error it throws there. Generally those errors are way more descriptive than Passenger because Passenger is probably running your application using the production environment.
Hey Ryan, do you need to Ruby 1.8.7? Why don't you install the latest 1.9.2 and Rails 3? I have the same environment and so far no problems. Here is a link for installing everything you need. Let me know if it helped! http://amerine.net/2010/02/24/rvm-rails3-ruby-1-9-2-setup.html
Salud!

i'm using passenger with apache and it cannot find my locally installed gems

if i use ./script/server my app runs fine but when i try to it it through passenger on apache it gives me
Missing the Rails 2.3.5 gem.
if i vendorize rails it seems that it finds it but then it fails for missing gems even though they are in vendor/gems.
ideally, i would not want to vendorize rails or gems for such a reason, but would expect that it picks up gems from my default home location ~/.gems
Sounds like it could be a permissions error or just the fact that passenger isn't running as the user where the gems are installed. Take a look at The user guide and user switching.
See my answer to a similar question "Passenger does not recognize locally installed gem, works with packed gems".

says if i develop a Ruby on Rails application using Rails 2.3.2, will that usually be compatible with Passenger on my hosting company?

says if i develop a Ruby on Rails application using Rails 2.3.2, will that usually be compatible with Passenger on my hosting company?
If i ssh to my hosting company and type rails -v, i get 2.2.2... so looks like they might be using Rails 2.2.2.
So if i develop a Rails app on my Macbook and ftp all files over there, will the Passenger there usually work well with the generated code with the current version of Rails?
Freeze rails into vendor/rails using the built in rake task. That way your app will ue the version of rails you want it to no matter where you deploy it.
rake rails:freeze:gems
And the easiest way to do a specific version I know of.
rake rails:freeze:edge RELEASE=2.3.2.1
Now your version of rails will go with you where you send your app.
You can unpack other gem dependencies into vendor/gems for any gem you are using and want to be sure that it is available where ever you deploy the application.
rake gems:unpack
And to ensure their dependencies go to:
rake gems:unpack:dependencies
I would also suggest that you verify that they are running the latest version of passenger.
I would verify the version of Passenger they have installed (or confirm they have it installed at all). I would also suggest you freeze your version of Rails.
Just second something for railsninja's answer .
First say, it won't work straightaway.
Is that host a vps to you or have sudo access somehow?
If yes, I suggest you to do rake gems:install instead of gems:unpack, because some of gems are os dependent e.g (Rcov, RedCloth...etc.)
I will ask the hosting company of their passenger's configuration, the important question will be if they use RailsSpawnMethod: smart or smart-lv2(default).If they use the smart method, then it is a better idea to freeze your gems and rails otherwise will have the compatible issue as you can find reference from passenger user manual about the RailsSpawnMethod.
It will be nearly 100% compatible if you freeze your gems(all the gems need to be declared correctly in the environment.rb with config.gem, e.g(config.gem 'will_paginate',:source=>"http://gems.github.com")) and RAILS!!!!!

Resources