viernes, 14 de agosto de 2009

Rails on share hosting environment

If you have a share hosting provider and you want to deploy a rails apps but you provider does not have rail on it or it has but not the specify rails version you require and you have ssh access to it, this steps may work for you

  1. Install ruby 1.8.7
    download ruby from ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz
    use wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz
    extract files tar xvzf ruby-1.8.7-p174.tar.gz
    change folder to ruby-1.8.7
    cd ruby-1.8.7
    change ruby configuration to install on the user folder
    ./configure --prefix=$HOME
    compile
    make
    make install

  2. Install ruby gems
    download gems from http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
    wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
    extract files tar xvzf rubygems-1.3.5.tgz
    change folder to cd rubygems-1.3.5
    execute and install the gems
    /home/tank/bin/ruby setup --prefix=$HOME
    this variable export GEM_HOME=/home/tank/ruby/gems
    (is best to set it on the user enviroment)
    you can do that adding it to your .bashrc or .bash_profile

  3. Install github if you need gems from github
    download github from http://www.kernel.org/pub/software/scm/git/git-1.6.4.tar.gz
    wget http://www.kernel.org/pub/software/scm/git/git-1.6.4.tar.gz
    extract tar xvzf git-1.6.4.tar.gz
    configure to install on the user home
    change to the git folder
    cd git-1.6.4
    ./configure --prefix=$HOME
    make
    make install

  4. Install you gems use like show here
    $HOME/bin/gem gem sources -a http://gems.github.com
    $HOME/bin/gem install mongrel
    $HOME/bin/gem install rails -v 2.3.2
    $HOME/bin/gem install mysql

  5. test your application
    go to you application folder and run
    $HOME/bin/ruby script/server
    6. to start the rails server you need to do this on your rails apps folder


  6. to start and stop rails server do
    $HOME/ruby/gems/bin/mongrel_rails mongrel::start -p 12004 --env=production -d -l log/mongrel.log
    $home/ruby/gems/bin/mongrel_rails mongrel::stop

  7. the .htaccess file on the the folder of the domain must have this lines this will redirect any web request from port 80 (http) to the 12004 port where our rails server is running.
    on this case the .htaccess file at $HOME/public_html/railsapps
    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^mysite.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.mysite.com$
    RewriteRule ^/?$ "http\:\/\/127\.0\.0\.1\:12004%{REQUEST_URI}" [P,QSA,L]
    RewriteRule ^(.*)$ "http\:\/\/127\.0\.0\.1\:12004%{REQUEST_URI}" [P,QSA,L]

One thing if you server does not have rails you can run ruby commands like gems, rails, rake with no need of adding the $HOME variable and bin path.

If you server has other version of ruby and rails then rake may not work it was not posible to make work so we have to relay on mysql command to create and load the application database.


Also i'm assuming you know or have the steps and gems require by your own rails apps.


Hope this help you, if not then get a VPS, where you can rule the machine, and this steps also may help you installing you ruby and rails but you need to consider not use mongrel and use passenger and not to use –prefix=$HOME when compiling.


Good luck.

No hay comentarios:

Publicar un comentario