in Linux, Rails

Install your own ruby on a shared host

Since I upgraded to Typo 4.0, and in the process rails 1.1.6 I have had a few occurrences where nanoRAILS would hang, several bloated processes would be sitting there and not respond, and the only option at that point was to kill all ruby processes once I realized what was happening, which could be several hours. Suffice it to say, this is not a good option.

So after struggling during last rails upgrade to 1.1 on my host, the next logical step is to also use my own version of ruby so I can have better control on its environment, and even apply patches if necessary.

The following steps apply on a lot of systems. More specifically, my host is DreamHost (aff), and as best I can tell, I’m on a host with Debian Sarge.

Build your own Ruby

Download ruby from http://www.ruby-lang.org. The latest version is currently ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.4.tar.gz

Create the makefile using

 ./configure prefix=[YOUR_OWN_RUBY_PREFIX]

Since you most likely don’t have root access, you need to override where ruby think it resides, and the way to do that is to set the prefix to somewhere into your home directory. Something like /home/USERNAME/ruby for example. From that point on, libraries, other builtin ruby files, gems will automatically install into your own ruby repository so you never have to worry about getting in trouble with an unforeseen upgrade.

Optionally, you can apply the patch used by Railsbench, with hardcoded default values because I haven’t figured how to set the environment variables for the dispatch.fcgi process (since apache in my case determines that). Download my version of rubygc.patch .

 patch gc.c rubygc.patch

Build and install ruby

 make
 make install

Additionally, so that the command line uses the same version of ruby, add this to your .bashrc or equivalent for your shel.

export PATH=[YOUR_OWN_RUBY_PREFIX]/bin:$PATH

Install your own gems

Now you are ready to install your own gems. Here’s the bare minimum you need.

First, install rubygems

 wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
 tar xzvf rubygems-0.9.0.tgz
 cd rubygems-0.9.0
 ruby setup.rb

Then install the minimum set of gems:

 gem install mysql
 gem install fcgi
 gem install rails --include-dependencies

Now, the only thing you need is to change the path to ruby in your dispatch file (dispatch.rb for mod_cgi, dispatch.cgi for regular cgi, and dispatch.fcgi for FastCGI/fcgid)

Typically, replace

#!/usr/bin/env ruby

by

#![YOUR_OWN_RUBY_PREFIX]/bin/ruby

Replace [YOUR_OWN_RUBY_PREFIX] by your own value you used earlier.

24 Comments

  1. Yes, indeed. And so far, the troubles from yesterday seem to be gone. Still crossing my fingers :)

  2. I installed my own version of Ruby and Rails/Gems on dreamhost but I still get the problem where the first request (after some idle time) takes up to a minute to load. I think this may be caused by Apache loading up the initial FCGI processes but I am also looking at my own app for slow points.

    Do you have any ideas (other than what’s on Dreamhost’s wiki) why this would be? Also, when will Dreamhost wake up and put mongrel on their servers :)

  3. David, I don’t seem to have this problem, but maybe just because I have request coming in often enough. I have heard of people adding a cron entry (using curl, you could use wget as well) to periodically wake up their server. You can check using _ps -eaf_ or _top_ whethher you have any _ruby_ or _dispatch.fcgi_ still running. If you do, then it should work (unless their are hung of course, but in this case you would get a 500 error after 120s).
    I wish dreamhost would support mongrel as well, or let us use proxying so we can run whatever we want.
    There is a page on dreamhost where you can cast your vote for mongrel support: [Vote for Mongrel on DreamHost](https://panel.dreamhost.com/index.cgi?tree=home.sugg&category=Software%20Installations&search=mongrel)

  4. When i first started using ruby I installed my own also. Then I became less interested in doing so when I could just apt-get it and it had things mostly the way I wanted them. the occasional configs here and there I find myself wanting but apt packaging has most everything a-ok. – ben @ http://rubyonrailsblog.com/

  5. Ben, I would indeed rather use apt-get. The point in this case though is that on a __shared host__ you can not use it (since you don’t have root access), and furthermore, you want better control as to when your environment changes as opposed to when your host decides to make the change.

  6. Does this still hold true? I followed the post to the letter, but now I get a Rails application failed to start error.

    I’ve killed any running fcgi just in case.

  7. Mark, your application can fail to start for a number of reasons. Check the web server log (apache?), at least the part your host provides, check your rails/log directory for any hints.
    Lastly, you can call your dispatch.fcgi and you might some errors you can not see in the logs.
    Depending on the error, you would have to figure out what the next step is.
    If you can’t figure it out, post any error you see here and someone might know a solution

  8. I tried using your patch but two of the hunks were rejected and kept the install from running. Is this a problem with Ruby 1.8.5?

  9. I tried these steps on 1and1.com shared linux developer package. It did not work when I created a rails skeleton and navigated in a browser to the root of the app. I get a 403 forbidden error in the apache log.

    [03/Jan/2007:20:12:18 -0500] “GET /sandbox/rails/blog/ HTTP/1.1” 403

    Perhaps some steps were left out? Some permissions changes?

    Thanks,

    Ed

  10. first, you need to make sure the absolute path to ruby is the right one. Then you can try running dispatch.fcgi by hand, you may learn something interesting.
    Next is to check the error.log for apache (assuming that’sone 1and1 uses). Also of interest is to check the ruby on rails log (development or production depending on how your setup is). Some of these logs are bound to show some error.
    Does the dispatch.fcgi get run as your user id? It is not, that may be a permission problem (403 is “forbidden”, usually).

  11. I tried to do that with my advantage netfirms.com host account. It gives me:
    bash: ./configure: /bin/sh: bad interpreter: Permission denied
    bash: make: command not found
    I tried in both /cgi-bin/ and /www/ subdirectories with the same result.
    By the way, they use pretty outdated ruby and rails:
    ruby -v
    ruby 1.8.2 (2004-12-25) [i386-freebsd4.10]

  12. hmm, this does not look good. No sh? no make? Are you sure your $PATH variable is set correctly?


  13. They give you /mnt/[coded]/www and /mnt/[coded]/cgi-bin for your staff.  Also, there is
     % ls -l
    total 60
    drwxr-xr-x   2 root  wheel  2048 Apr  9  2006 bin
    drwxr-xr-x   2 root  wheel   512 Dec  8  2005 etc
    drwxr-xr-x  11 root  wheel  1024 Dec  3  2005 include
    drwxr-xr-x   2 root  wheel   512 Dec  3  2005 info
    drwxr-xr-x   9 root  wheel  1536 Jun 12  2006 lib
    drwxr-xr-x   2 root  wheel   512 Dec  3  2005 misc
    drwxr-xr-x   6 root  wheel   512 Dec  3  2005 mysql-test
    -rw-r--r--   1 root  wheel  7782 Dec  2  2005 openssl.cnf
    drwxr-xr-x   6 root  wheel   512 Dec  3  2005 php5
    drwxr-xr-x   2 root  wheel   512 Jun 12  2006 sbin
    drwxr-xr-x   8 root  wheel   512 Dec  3  2005 share
    drwxr-xr-x   7 root  wheel  1024 Dec  3  2005 sql-bench
    
    Well, you see it's all root.
    
    Also, make is not available -- you cannot compile anything.
    
    I tried some different things.
    ruby setup.rb config --prefix=~/rubygems
    setup.rb:696:in `expand_path': Permission denied - getcwd (Errno::EACCES)
            from setup.rb:696:in `initialize'
            from setup.rb:687:in `new'
            from setup.rb:687:in `instance'
            from setup.rb:681:in `invoke'
            from setup.rb:1359
    
    Also, looks like they have not fastcgi.
    
    Their ruby is old:
    =========== /usr/local/nf/lib/ruby ======T=====
    n         Name           │ Size │  Date  │Time
    ..                       │  Up  │06/12/06│13:54
    1.8                      │Folder│12/03/05│00:14
    gems                     │Folder│12/03/05│00:14
    site_ruby                │Folder│12/03/05│00:14
    
    I wish I could tweak my profile
    
    /usr/local/nf/etc
    
    # /etc/profile
    #
    
    if [ "$SHELL" = "/usr/local/nf/sbin/sshshell" ]
    then
        # double check uid/gid
        if [ "$EUID" != "$UID" ]
        then
            echo "euid ($EUID) != uid ($UID)" >&2
            exit 1
        fi
    
        if [ "$EUID" -lt 1500 ]
        then
            echo "euid ($EUID) < 1500" >&2;
            exit 1
        fi
    
        umask 0022
        ulimit -c 0
        ulimit -d 32000
        ulimit -f 10000000
        ulimit -l 3000
        ulimit -m 18000
        ulimit -n 20
        ulimit -s 10000
        ulimit -t 20
        ulimit -u 12
        ulimit -v 8000000
    
        if [[ "$GECOS" == *sshallow=0* ]]
        then
            echo
            echo "  *********************************"
            echo "  *                               *"
            echo "  *   SSH ACCESS IS NOT ENABLED   *"
            echo "  *                               *"
            echo "  *********************************"
            echo
            exit 0
        fi
    
        if [[ "$GECOS" == *websuspend=[^0]* ]] || [[ "$GECOS" == *sshsuspend=1* ]]
        then
            echo
            echo "  ************************************"
            echo "  *                                  *"
            echo "  *   SSH ACCESS HAS BEEN DISABLED   *"
            echo "  *                                  *"
            echo "  ************************************"
            echo
            exit 0
        fi
    
        unset GECOS
        unset SSH_CONNECTION
        unset MACHTYPE
        unset OSTYPE
        export PATH=/bin:/usr/bin:/usr/local/bin:/usr/local/nf/bin
        export HOME=/mnt/${HOME##*/}/www
        export HISTFILE=${HOME}/.bash_history
        export SHELL=/usr/local/bin/bash
        export NF_MYSQL_HOST=${NF_MYSQL_HOST/10.8.12.*:/10.100.21.0:}
        export LD_LIBRARY_PATH=/usr/local/nf/lib
    
        PS1="$USER % ";
    
        cd $HOME
    
    fi
    
    but it is not editable and requires root, too.
    
    Pretty sad.
    


  14. Does not look good indeed. You should be able to override your profile by creating a .profile (or .bash_login) file in your home directory (~)

    Since the system appears to be freebsd, you may be able to find binaries of make and copy them over, but it may be time for a new home…

  15. For the long run, yes, I better find the more friendly host, but, actually, I got this deal as $10/yr plus 2 free domains, so, if I leave I have to pay for domains anyways.

    Seems like a good idea of yours to try to find binaries of “make” and what not and copy them over to my local directory! Unfortunately, FreeBSD used by provider is pretty old (4.1), and freebsd.org has moved it to
    this archive, and it is restricted by passworded by some unclear weird reason!

    Because all I need so far is to extract the “make” binary, I found
    another resource, but I don’t actually know where can I get the desirable “make” among all those file.

    Sorry I’m too desperate to install my RoR applications on even creepy host, and also feel guilty to distract you so often. I think my case is too “unusual”. But who knows what iif a lot of netfirms.com users want to do the same? RoR is very popular, and gains more and more each day, deminishing ubiquitous PHP — pretty soon such providers without good RoR will be out of business or forced to upgrade.

    Probably, for me, it would be just easier to go to with hosts already supporting Mongrel and Ruby (no need in fastcgi etc):

    Still, I feel like I can win a real freedom, if even being prisoned in the cell of the jailed shell provided by netfirms.com, I could install mongrel and the last rail and gems. After all, any host can change something and never give me root (which I actually don’t need). So, your ninja skills you shared with us, are pretty valuable, no matter what. All I need is the plans with shell access, and it’s pretty attractive to install the latest and the greatest and customized for yourself as if almost you have dedicated server.

    Thank you in advance!

  16. It is sounding worse by the minute. You may really be out of luck, but it is true that the price sounds hard to beat.

    Just out of curiosity, did you try to work with netfirms support? Maybe they can help you with part of it?

  17. It would be nice to find the ready-made binary of “make” for i386-freebsd4.10. But I’m not sure it could be enough to successfully compile anything inside my local directory because of dependencies etc.

    netfirms.com “support” is a joke. You’re lucky if after waiting for a week or two, somebody (probably from sales) just refers you to their scarce and buggy 1 page manual.

    I’m under impression that nobody really uses Ruby on Rails on netfirms.com. Actually, netfirms.com is not bad hosting — they provide you not only *nix with PHP/Perl etc,, but also .NET/Windows platform. Could be handy in some case if you have such customers

    I am going to try couple of my old ASP.NET 2.0 projects next week then, but, as a matter of fact, after working with Ruby, I hate to look back to Java/C# strong-type languages.

Comments are closed.