24

What would be a reasonable and logical directory into which to deploy my production Rails apps on a Linux system?

Some candidates...

/var/rails  <= There's a /var/www so this would be consistent with that 
               pattern. But I.T. guys have complained about stuff in /var 
               before.

/home/my_home_dir/rails  <= OK, not /var, but I'm not the only developer. 
                            Seems like it really ought to be a systemwide
                            location.

/home/rails  <= I don't know. That just seems weird.

/rails  <= Seems even weirder.

What is the least astonishing, most normal thing to do here?

(Background info -- a Rails app is a bunch of server side code written in Ruby along with a public dir containing JavaScript, CSS, and maybe a little HTML. The public dir is mapped to an Apache vhost. Apache handles the Ruby code through a module called Passenger or mod_rails.)


Thanks for the help, all. I think I'm going to go with /opt/deployed_rails_apps. (I like long, expository directory names, and tab completion.) /var/... is also a good place, but I've gotten stern grumbling from I.T. when I tried to deploy stuff there. If it were my own machine I might go with /var or /srv.

Agvorth
  • 2,429
  • 4
  • 28
  • 29
  • You may want to see this other related question: http://serverfault.com/questions/29129/where-to-place-web-content-for-multiple-domains-on-a-rhel-based-server/29134#29134 – chmeee Jul 08 '09 at 20:53
  • a side question but still related i was working on a rails project contained in the ~/Documents/quotes (directory) and after deploying it, found much to my surprise some 6 months later, that the identical folder structure is also in /var/www/html/quotes - when deploying does rails copy it to the var folder? I have no idea how it all got there from the other directory. any help would be appreciated – BenKoshy Feb 01 '16 at 05:15

6 Answers6

7

You may want to follow the Filesystem Hierarchy Standard (FHS) and place it in

/srv : Data for services provided by this system

EDIT:

I wouldn't place it in /opt:

/opt : Add-on application software packages

It's purpose says:

/opt is reserved for the installation of add-on application software packages.

A package to be installed in /opt must locate its static files in a separate /opt/ or /opt/ directory tree, where is a name that describes the software package and is the provider's LANANA registered name.

I don't think a developed application is a 'software package'.

The rationale for /srv is

This main purpose of specifying this is so that users may find the location of the data files for particular service, and so that services which require a single tree for readonly data, writable data and scripts (such as cgi scripts) can be reasonably placed.

I understand that a rails app is a cgi script and should be placed in /srv.

chmeee
  • 7,270
  • 3
  • 29
  • 43
  • I wouldn't be too fanatical about what the FHS says. The most important thing is to keep your custom packages away from the operating system files. And the best places for that are "/usr/local" and "/opt". – Andrioid Jul 09 '09 at 21:48
  • 1
    I'm not fanatical, but I like their filesystem organization. In any case I agree that /usr/local and /opt are good for software packages, but I don't think that a rails app is a software package – chmeee Jul 09 '09 at 22:28
  • 1
    Based on what the FHS says, `/srv` seems like the most fitting directory to me. I'm using `/srv/rails/application_name`. – Teemu Leisti Mar 15 '14 at 18:47
7

On CentOS Linux distributions (and subsequently RedHat), when you install the httpd package (for Apache 2), it creates /var/www, and expects that your vhosts point to your web content here. The default vhost is typically dumped in /var/www/htdocs, and subsequent sites/apps should be put in /var/www/sitename.

The actual location shouldn't matter much, but it's common to see /opt/www/sitename, /var/www/sitename, or simply /opt/www or /var/www.

You've already stated a few of the reasons why some of the other locations (like /home) are not really suited for this.

Personally, I prefer /var/www/sitename since it's friendly to Apache and Rails, and is system-wide.

Diamond
  • 8,791
  • 3
  • 22
  • 37
Kevin Elliott
  • 201
  • 1
  • 4
  • 1
    Web apps should go in /var/www, especially if they are served through something like a proper webserver like Apache of Lighttpd. The more so, since SELinux policies will be properly applied to a Rails app in /var/www and not in /opt. – wzzrd Jul 09 '09 at 11:04
6

I think /opt would be the place for an application like this. I agree with following the FHS as suggested by chmeee, but I don't agree that a Rails app is a service per se.

Argalatyr
  • 276
  • 4
  • 11
  • It's difficult to tell, actually the rails software is isntalled in the system somewhere (as a gem or package), what he wants to place is the directory structure for the 'service', the actual application that uses rails to serve something. – chmeee Jul 08 '09 at 20:52
  • I recognized he's talking about an app he's created (hence, "a Rails app"), rather than Rails itself. Either way, /srv seems wrong. – Argalatyr Jul 08 '09 at 21:49
0

In debian/ubuntu based system such applications are usually installed in /usr/share folder (i.e. /usr/share/ruby), since they are non-compiled files (which would go into /usr/lib). Since your application is not a standard application you would probably put it in /usr/local/share preventing it there being overwritten by any system updates.

/opt is certainly also a possibility here.

txwikinger
  • 903
  • 7
  • 14
0

I usually put them in /opt/app_name.

fields
  • 690
  • 1
  • 10
  • 21
0

I keep my deploys in

/home/www.example.com/application

The arguments:

Home will contain all the moving parts of a single website. If I have more websites I will know where to find them.

Ivailo Bardarov
  • 179
  • 1
  • 4