Configuring a Rails 4 app for production in a subdirectory under Apache
There are a few assumptions I'm going to make in order to try and answer your question.
I'm assuming there is a static site served at
myurl.com
and that you only want the Rails app to be served onmyurl.com/myapp
I'm assuming your shared hosting provider prefers FastCGI as a way to serve Rack apps (Rails)
Based on those assumptions, I believe that if you:
- Move your Rails app under the
~/html/myapp
folder - Add a
.htaccess
file to~/html/myapp/public
with contents:
AddHandler fastcgi-script .fcgi Options +FollowSymLinks +ExecCGI RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L] ErrorDocument 500 "Rails application failed to start properly"
- Add a
dispatch.fcgi
file to~/html/myapp/public
with contents:
ENV['RAILS_ENV'] ||= 'production' ENV['GEM_HOME'] = File.expand_path('your_gem_home') require 'fcgi' require File.join(File.dirname(__FILE__), '../config/environment.rb')
chmod +x ~/html/myapp/public/dispatch.fcgi
the app should start just fine and route just fine...
I don't think you need to worry about setting config.action_controller.relative_url_root
.
I would also install your gems using bundle install --deployment
prior to deploying your app.
Finally, the reason you're not getting a root route is because there is no:root :to => 'controller#action'
in your config/routes.rb
Hope this helps and if not, check out:
Dreamhost - Rails 3 and FastCGI and FastCGI setup which includes some hints about using ENV['RAILS_RELATIVE_URL_ROOT']