Rails app deployment experience in BlueHost

Source: Internet
Author: User
Tags cpanel subdomain subdomain name

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.