| 1 |
== link:index.html[Index] -> link:cookbook.html[Cookbook] |
|---|
| 2 |
|
|---|
| 3 |
Cookbook: Setting up Ruby on Rails |
|---|
| 4 |
---------------------------------- |
|---|
| 5 |
|
|---|
| 6 |
Setting up a Rails application to run with Cherokee and FastCGI is not |
|---|
| 7 |
only easy. It is also the best possible solution to manage the load |
|---|
| 8 |
among one or many Rails servers, using an extremely efficient web |
|---|
| 9 |
server to manage the web part and leaving as many free resources as |
|---|
| 10 |
possible to Rails. |
|---|
| 11 |
|
|---|
| 12 |
Of course you will need a working Rails installation for this to |
|---|
| 13 |
succed. You can set this up easily. If you have Ruby and Ruby Gems |
|---|
| 14 |
installed, you can directly install the 'Rails' gem like this: |
|---|
| 15 |
|
|---|
| 16 |
---- |
|---|
| 17 |
# gem update --system |
|---|
| 18 |
# gem install rails |
|---|
| 19 |
---- |
|---|
| 20 |
|
|---|
| 21 |
Note that on Debian based systems you don't even need to install |
|---|
| 22 |
Rubygems. There is already a package that will install every needed |
|---|
| 23 |
dependency: |
|---|
| 24 |
|
|---|
| 25 |
---- |
|---|
| 26 |
# apt-get install rails |
|---|
| 27 |
---- |
|---|
| 28 |
|
|---|
| 29 |
The installation of the 'Rails' gem directly would also work, but note |
|---|
| 30 |
that you cannot execute the first command because it is disabled by |
|---|
| 31 |
default. |
|---|
| 32 |
|
|---|
| 33 |
---- |
|---|
| 34 |
# gem update --system |
|---|
| 35 |
ERROR: While executing gem ... (RuntimeError) |
|---|
| 36 |
gem update --system is disabled on Debian. RubyGems can be updated \ |
|---|
| 37 |
using the official Debian repositories by aptitude or apt-get. |
|---|
| 38 |
---- |
|---|
| 39 |
|
|---|
| 40 |
Once you are done with that, you must deploy your Rails project: |
|---|
| 41 |
|
|---|
| 42 |
---- |
|---|
| 43 |
$ rails example |
|---|
| 44 |
---- |
|---|
| 45 |
|
|---|
| 46 |
You can do so wherever you want, but the usal recommended way of doing |
|---|
| 47 |
this is by deploying it outside of your web root path and then |
|---|
| 48 |
creating a symbolic link. This is simply to protect from exposure all |
|---|
| 49 |
the files that do not need to be in your document root. |
|---|
| 50 |
|
|---|
| 51 |
Assuming you deployed the `example` project in `/home/foo/example`, |
|---|
| 52 |
and you have writing permissions to your web path, `/var/www`, simply |
|---|
| 53 |
type: |
|---|
| 54 |
|
|---|
| 55 |
---- |
|---|
| 56 |
$ ln -s /home/foo/example/public /var/www/example |
|---|
| 57 |
---- |
|---|
| 58 |
|
|---|
| 59 |
Now you are ready to configure Cherokee. You only need to know that |
|---|
| 60 |
you can spawn the FastCGI process using a script that is already in |
|---|
| 61 |
your deployed project. In this case, |
|---|
| 62 |
`/home/foo/example/script/process/spawner`. |
|---|
| 63 |
We will be using the default parameters (3 instances starting at port |
|---|
| 64 |
8000) but you can fine tune this using the many parameters provided by |
|---|
| 65 |
the script. |
|---|
| 66 |
|
|---|
| 67 |
The process is fairly simple. Set up a new rule for this new path and |
|---|
| 68 |
manage it with the FastCGI handler. |
|---|
| 69 |
|
|---|
| 70 |
.Common CGI options |
|---|
| 71 |
Under `Common CGI options` make sure to check the `Error handler` box and |
|---|
| 72 |
uncheck `Check file`. This is to prevent possible errors with the |
|---|
| 73 |
`INFO_PATH` generation that can happen when an application, in this |
|---|
| 74 |
case 'Rails', manages the whole subtree. This is mentioned in the |
|---|
| 75 |
link:modules_handlers_cgi.html[Common CGI] section of the |
|---|
| 76 |
documentation. It is a good idea to enable the `Error handler` |
|---|
| 77 |
checkbox since it will help you determine if an error is associated |
|---|
| 78 |
with your Ruby on Rails application or with Cherokee. This, however, |
|---|
| 79 |
is not required. |
|---|
| 80 |
|
|---|
| 81 |
image::media/images/cookbook_ror_common.png[Common CGI options] |
|---|
| 82 |
|
|---|
| 83 |
.FastCGI specific |
|---|
| 84 |
Under `FastCGI specific` make sure to add the hosts providing the |
|---|
| 85 |
service. Do this by adding one or more |
|---|
| 86 |
link:config_info_sources.html[Information Sources]. |
|---|
| 87 |
|
|---|
| 88 |
Note that, in the definition of the informaction source, you will have |
|---|
| 89 |
to manually launch the `spawner` if you use a `Remote host` as |
|---|
| 90 |
`Information source` instead of a `Local interpreter`. |
|---|
| 91 |
|
|---|
| 92 |
You will simply have to add as many sources as desired, for instance |
|---|
| 93 |
our example uses the default values to set up ports 8000 through |
|---|
| 94 |
8002. These sources will be nicknamed *ror0*, *ror1* and *ror2*. |
|---|
| 95 |
|
|---|
| 96 |
[grid="rows"] |
|---|
| 97 |
`~~~~~~~~~~~~~~`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 98 |
Host , Interpreter |
|---|
| 99 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 100 |
localhost:8000 , `/home/foo/example/script/process/spawner fcgi` |
|---|
| 101 |
localhost:8001 , `/home/foo/example/script/process/spawner fcgi` |
|---|
| 102 |
localhost:8002 , `/home/foo/example/script/process/spawner fcgi` |
|---|
| 103 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 104 |
|
|---|
| 105 |
If any of those ports was not reachable, the `interpreter` command |
|---|
| 106 |
would be launched and the fallen one would be reinstantiated. |
|---|
| 107 |
|
|---|
| 108 |
Here is a snapshot to show the creation of *ror0*. The rest are |
|---|
| 109 |
similar using the port variation detailed above. |
|---|
| 110 |
|
|---|
| 111 |
image::media/images/cookbook_ror_fcgi.png[FastCGI specifics] |
|---|
| 112 |
|
|---|
| 113 |
Once everything is done you can check if Rails is really |
|---|
| 114 |
working. Simply navigate to the path configured by your rule, |
|---|
| 115 |
http://localhost/example/ for instance, and you should see some notes |
|---|
| 116 |
about your recently created project. |
|---|
| 117 |
|
|---|
| 118 |
image::media/images/cookbook_ror.png[Rails example] |
|---|