Tag Archives: ror

Ruby on Rails dev environment on a remote server

A friend asks:

…so I’m trying to install RoR on a remote server of mine, but it seems that RoR development methodology wants you to test your webpages on localhost:3000. But, obviously, since the computer is in the cloud, I can’t just well pull up a webpage on the console. Is there an easy way to get development pages to show up on a web browser that’s not local?

Ruby on Rails was designed by a bunch of guys writing code locally on their Macs so it’s easy to see why they assume a local web sever is a solution. So there are a couple of options.

1) use mod_passenger w/Apache for all your environments. This requires quite a bit more work but it’s the way you’d want to do it for any larger environment. Google will teach you all you want about this, but I recommend it only when your environments are mature and you are needing to scale out production.

2) Tell Apache to pass dev.yourdomain.com to localhost port 3000. You’d need to set up a dev hostname in DNS and point it at the server as well. It would look like this in the apache config:

<VirtualHost *:80>
ServerAdmin         webmaster@domain.com
ServerName          dev.domain.com
ProxyPreserveHost   On
ProxyPass           /      http://127.0.0.1:3000/
ProxyPassReverse    /      http://127.0.0.1:3000/
</VirtualHost>

3) Similar as above, but if you don’t want to mess with DNS, you can
proxy based on the URL:

ProxyPass        /foo http://127.0.0.1:3000
ProxyPassReverse /foo http://127.0.0.1:3000

more on mod_proxy here: http://httpd.apache.org/docs/2.0/mod/mod_proxy.html

4) Use ssh to tunnel requests from your local machine out to the server (ssh tunnel). ssh will forward the tcp packets across the pipe towards a host you specify on the other end. In this case, you’d tell it to send localhost port 3000 (on your laptop) across the pipe and out to localhost port 3000 on the server. This will only provide access for you (since it’s a private tunnel).

ssh -L 3000:127.0.0.1:3000 host.server.com

Then in your browser surf to http://127.0.0.1:3000

For speed, I’d probably do #4 to test that things are working and go up towards #1 as you get your environment more set up. #1 is the most amount of work (mod_passenger can be a PITA).