title: How do I deploy a Sinatra app with Nginx and Passenger?
body: <p>I'm on a Dreamhost virtual private server. I have never written a Sinatra app, or any other Rack app before. I'm just trying to get a Hello World app to run but I keep getting the Passenger error page with the error:</p>
  
  <pre><code>no such file to load -- rack
  </code></pre>
  
  <p>I have created <code>public/</code> and <code>tmp/</code> in the domain / app root.</p>
  
  <p>Also in the app root is this <code>config.ru</code>:</p>
  
  <pre><code>require 'rubygems'
  require 'sinatra'
  require 'myapp'
  
  run Sinatra::Application
  </code></pre>
  
  <p>which I pulled from the Passenger on Nginx docs, <a href="http://modrails.com/documentation/Users%20guide%20Nginx.html#_sinatra" rel="nofollow">Sinatra section</a>.</p>
  
  <p>Finally, this is <code>myapp.rb</code>, which I pulled from the top of the Sinatra <a href="http://www.sinatrarb.com/intro.html" rel="nofollow">Intro doc</a>.</p>
  
  <pre><code># myapp.rb
  require 'sinatra'
  
  get '/' do
    'Hello world!'
  end
  </code></pre>
  
  <p>How can I get this to work?</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here are the top three lines of the stack trace given on the Passenger error page:</p>
  
  <pre><code>0 /usr/lib/ruby/1.8/rubygems/custom_require.rb 31 in `gem_original_require'
  1 /usr/lib/ruby/1.8/rubygems/custom_require.rb 31 in `require'
  2 /dh/nginx/passenger/lib/phusion_passenger/rack/application_spawner.rb 145 in `load_rack_app'
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I suspect I have discovered <em>why</em> Passenger can't find rack, but I still haven't figured out a solution. At the top of my <code>nginx.conf</code> is this line:</p>
  
  <pre><code>user dhapache;
  </code></pre>
  
  <p>It would seem that Passenger is looking for the gems either as <code>dhapache</code> or as <code>root</code> and I'm not sure which it is based on the process list given from <code>ps aux | less</code>:</p>
  
  <pre><code>root     PassengerNginxHelperServer /dh/nginx/passenger ruby 3 4 0 6 0 300 1 nobody 999 150 /tmp/passenger.19012
  root     Passenger spawn server
  dhapache nginx: worker process
  dhapache nginx: worker process
  root     nginx: master process /dh/nginx/bin/nginx-be -c /dh/nginx/servers/httpd-ps77303/nginx.conf -p /dh/nginx/servers/httpd-ps77303/var/
  </code></pre>
  
  <p>However, in either case the gem paths listed by <code>gem env</code> point only to places where there are no gems. If Passenger is looking for gems in those places, it won't find any.</p>
  
  <p>Gem paths from <code>sudo -u dhapache gem env</code></p>
  
  <pre><code>/var/lib/gems/1.8
  /root/.gem/ruby/1.8
  </code></pre>
  
  <p>Gem paths from <code>sudo -u root gem env</code></p>
  
  <pre><code>/var/lib/gems/1.8
  /dh/apache/.gem/ruby/1.8
  </code></pre>
  
  <p>In both cases, the first (identical) directory is empty and the second directory listed does not exist.</p>
  
  <p>In this server setup, the applications are hosted under <code>/home/[username]/[domain]/</code> and the local gems are in <code>/home/[username]/.gems/</code>. Running <code>gem env</code> as the app user shows the local gem path.</p>
  
  <p>How do I get Passenger to find my local gems?</p>