Installing Ruby and Rails on a 1&1 Server

One organization I do a lot of work with hosts their sites on a 1&1 Managed Server. Essentially, only their sites and applications are running on the server, but 1&1 manage all of the sysadmin work, and don’t provide root access. I have a number of misgivings about the configuration of the server, particularly the fact that the user’s root folder is also the document root for their main domain, but 1&1 have been good about keeping PHP up to date, and we don’t have to worry about being woken at 3am to fix stuck processes. Unfortunately, Ruby hasn’t been treated to the same attention as PHP and the system version is still languishing at version 1.8.1, which won’t handle rails for us.

We entered into a round of emails to try and persuade 1&1 to upgrade ruby for us, and maybe even install gem and rails system-wide, but after a number of confusing messages where it wasn’t clear whether their answers actually applied to the plan we were on (“you need a linux server for that”/”we have a linux server”, “you need a dedicated server”/”we have a dedicated server”) we gave in and I realised that if I wanted rails I’d have to install it myself.

It turned out to be a very straightforward process. Compiling ruby and gems with appropriate prefixes (./configure –prefix=/my/preferred/folder) got them in place, and from there I was able to install the rails gems. It’s important to check that your installation folder is blocked by the web server and to put a relevant .htaccess file in place if not. You don’t want a curious visitor or malicious attacker playing with your binaries. You’ll also want to add your new bin folder to your default path by editing your .bash_profile file to add a line like:

export PATH=~/usr/bin:$PATH

With that done, changing the shebang in dispatch.cgi was enough to get the application up and running using CGI, which was enough for us to start testing applications, but would quickly become too slow once those apps are in production.

FastCGI can be activated through the ‘Server Administration > Advanced Settings’ option in the control panel. I did that, and then tried to install the fcgi gem:

gem install fcgi

It installed successfully, but building the documentation threw a sequence of errors about undefined symbols. Unfortunately when I switched my .htaccess settings so that FastCGI I received an ‘application could not start properly’ error. Being short of time, and having rails frozen into my application directory, I decided to go in and edit
[APP]/vendor/rails/railties/lib/fcgi_handler.rb directly, changing

require 'fcgi'

to include the full path to my newly installed fcgi gem.

That worked, and I now have a working, fastcgi-based rails application running on the server.

Tags: , ,

8 comments

  1. You have to persuade them with candy. 😀 I used to work for people, who knew the support at 1&1 and virtually hosted everything with them. I met the head of support at Cebit once, went for drinks and so on. We bribed them with candy. 😉

  2. Thanks a lot!
    I did’nt know it would be possible, but now I’ve got Rails on 1&1. 🙂

  3. Just a precision:

    I add to install mysql via:
    gem install mysql

    to avoid “Before updating scaffolding from new DB schema, try creating a table for your model” problem

  4. Hi again!

    I managed to launch a Webrick server on 0.0.0.0:3000, connect to a mysql database and scaffold a small app.
    But now I would like to deploy this app thanks to fcgi, but cannot find ‘Server Administration > Advanced Settings’ to activate it.
    And I don’t know neither what to write in my dispatch.cgi or in .htaccess. :-/

    My rails app is in
    ~/rails/test
    and ruby, rails and gem binaries are installed in
    ~/usr/bin/

    Could you please explain me what I should do to get rails up and running?

    Thanks a lot,

    Eric

  5. Eric:

    I believe the file you want is .htaccess, read the file, there is a section there that says Rewriterule blahblah dispatch.cgi, you need to change this so it becomes Rewriterule blahblah dispatch.fcgi (add f).

    Launching servers using script/server generally is used only during development. When launching into production mode you need to use the dispatchers, in this case dispatch.fcgi since you want FCGI.

  6. Thanks so much for sharing that information !!!

  7. Could you please let us have more information how you compiled ruby? Because I only run into openssl errors, really no fun…

  8. […] a work on process » Installing Ruby and Rails on a 1&1 Server (tags: ruby 1and1) […]