Google search has published many articles on "bluehost rails" (mostly in English ).
For more information, see!
But there are a few special points to note.
1. Add a subdomain name
Go to cPanel and click subdomains under Domains. Then, Add.
(When you generate rails, you forget to add a subdomain name or link to the subdomain name .)
2. The first line of dispatch. fcgi and dispatch. rb (under the publice directory.
Because BlueHost is a virtual unix system, it must be changed #! /Usr/bin/ruby
(If a program is developed in windows, users often forget to change the first line to the ruby path in unix)
3. Add Apache handler to process the. fcgi file.
There are two handler by default, but there is no handler for. fcgi.
After entering cPanel, go to Apache handlers under Adance and click to enter.
Add handler: fcgid-script,
Extension (s):. fcgi.
(If this handle is not added, the dispatch. fcgi file cannot be parsed .)
3. Modify dispatch. fcgi
Add
ENV ['rails _ env'] = 'production'
ENV ["GEM_HOME"] = "/home/[User_Name]/ruby/gems"
ENV ["GEM_PATH"] = "/home/[User_Name]/ruby/gems:/usr/lib/ruby/gems/1.8"
(Here [User_Name] is your user name)
4. Modify permissions (this is also important)
Cd public/
Chmod-R 755 *
Cd tmp/
Chmod-R 755 *
Cd log/
Chmod-R 755 *
Chmod-R 755 public/
Chmod-R 755 tmp/
Chmod-R 755 log/
Do not open the permission to 777. Otherwise, an error occurs.
Below are several important files (public directory)
. Htaccess:
AddHandler fcgid-script. fcgi
# Options + FollowSymLinks + ExecCGI
SetEnv RAILS_ENV production
RewriteEngine On
RewriteRule ^ $ index.html [QSA]
RewriteRule ^ ([^.] +) $ response 1.html [QSA]
RewriteCond % {REQUEST_FILENAME }! -F
RewriteRule ^ (. *) $ dispatch. fcgi [QSA, L]
Dispatch. fcgi:
#! /Usr/bin/ruby
ENV ['rails _ env'] = 'production'
ENV ["GEM_HOME"] = "/home/fortyaga/ruby/gems"
ENV ["GEM_PATH"] = "/home/fortyaga/ruby/gems:/usr/lib/ruby/gems/1.8"
Require File. dirname (_ FILE _) + "/../config/environment"
Require 'fcgi _ handler'
RailsFCGIHandler. process!
Dispatch. rb:
#! /Usr/bin/ruby
Require File. dirname (_ FILE _) + "/../config/environment" unless defined? (RAILS_ROOT)
Require "/usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/dispatcher"
ADDITIONAL_LOAD_PATHS.reverse.each {| dir | $:. unshift (dir) if File. directory? (Dir)} if defined? (Apache: RubyRun)
Dispatcher. dispatch
5. When an Application error occurs, run./Dispatch. fcgiCheck whether an error has occurred.
Check the Log error logs in cpanel.
6. If error logs is encountered under cpanelPremature end of script headersWhen an error occurs, the file format may be incorrect. In most cases, the app file is in dos format and can be converted using dos2unix filename.
Here, we need to upload .htaccess,dispatch.fcgitwo files. We recommend that you use tar.gz to compress as much as possible when downloading the application program.
7. After the DATABASE is created, change the DATABASE encoding ALTER database' [your_database] 'default character set utf8 COLLATE utf8_general_ci