public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Hongli Lai (Phusion) (author)
Mon May 12 17:29:35 -0700 2008
commit  4c186ace8589aef55a12d3636aa5004ee9b96344
tree    d11b987a5eea8e45b84c01b1cee9c608f21a2faa
parent  0337f4f4b88f5067f218b3df64707d60058a59dd
passenger / doc / Users guide.txt
100644 833 lines (641 sloc) 31.748 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
= Passenger users guide =
 
image:images/phusion_banner.png[link="http://www.phusion.nl/"]
 
Passenger is an Apache module, which makes deploying Ruby on Rails applications
on Apache a breeze. It follows the usual Ruby on Rails conventions, such as
"Don't-Repeat-Yourself" and ease of setup.
 
This users guide will teach you:
 
- How to install Passenger.
- How to configure Passenger.
- How to deploy a Ruby on Rails application.
- How to solve common problems.
 
This guide assumes that the reader is somewhat familiar with Apache and with
using the commandline.
 
 
== Supported operating systems ==
 
Passenger works on any POSIX-compliant operating system. In other words:
practically any operating system on earth, except Microsoft Windows.
 
Passenger has been tested on:
 
- Ubuntu Linux 6.06 (x86)
- Ubuntu Linux 7.10 (x86)
- Debian Sarge (x86)
- Debian Etch (x86)
- Debian Lenny/Sid (x86)
- CentOS 5 (x86)
- Red Hat Enterprise Linux 5 (x86)
- Gentoo, March 14 2008 (AMD64)
- FreeBSD 6.1-RELEASE (x86)
- MacOS X Tiger (x86)
- MacOS X Leopard (x86)
 
Other operating systems have not been tested, but Passenger will probably work
fine on them. Please
link:http://code.google.com/p/phusion-passenger/issues/list[report a bug]
or
link:http://groups.google.com/group/phusion-passenger[join our discussion list]
if it doesn't.
 
 
== Installing Passenger ==
 
=== Generic installation instructions ===
 
[[install_passenger]]
==== Overview of download and installation methods ====
 
There are two ways to install Passenger:
 
1. By installing the Passenger gem, as instructed on the
   link:http://www.modrails.com/install.html[``Install'' page on the Passenger website].
2. By downloading a native Linux package (e.g. Debian package) from the Passenger website.
3. By downloading the source tarball from the Passenger website
   ('passenger-x.x.x.tar.gz').
 
In our opinion, installing the gem or the native package is easiest.
 
Passenger provides an easy-to-use installer for installing the Passenger
Apache module ('mod_passenger').
 
TIP: You might have to run the installation commands in the following sections
as 'root'. If the installer fails because of permission errors, it will tell
you.
 
[[specifying_correct_apache_install]]
==== Specifying the correct Apache installation ====
 
NOTE: You can skip this section if you've installed Passenger via a native Linux
package, because no compilation is necessary.
 
If your system has multiple Apache installations (this is likely the case on
MacOS X), then you will need to tell the Passenger installer which one to use.
If you only have one Apache installation (the case on most Linux systems), then
you can skip this section because Passenger will automatically detect it.
 
Every Apache installation has its own `apxs` program. You will need to tell
Passenger the location of this program, by specifying the `APXS2` environment
variable. Suppose that you want to use the Apache installation in
'/opt/apache2'. Then, assuming that the corresponding `apxs` program is located
'/opt/apache2/bin/apxs', type:
----------------------------------
export APXS2=/opt/apache2/bin/apxs
----------------------------------
 
NOTE: On some systems, the `apxs` program might be called `apxs2`, and it might
be located in the `sbin` folder instead of the `bin` folder.
 
[[specifying_ruby_installation]]
==== Specifying the correct Ruby installation ====
 
NOTE: You can skip this section if you've installed Passenger via a native Linux
package, because no compilation is necessary.
 
If your system has multiple Ruby installations (this is likely the case on
MacOS X), then you will need to tell the Passenger installer which one to use.
If you only have one Ruby installation (the case on most Linux systems), then
you can skip this section because Passenger will automatically detect it.
 
To specify the Ruby installation, prepend your Ruby installation's `bin`
directory to the `PATH` environment variable. For example, if you have the
following Ruby installations:
 
- /usr/bin/ruby
- /opt/myruby/bin/ruby
 
and you want to use the latter, then type:
 
----------------------------------
export PATH=/opt/myruby/bin:$PATH
----------------------------------
 
 
==== Installing via the gem ====
 
Please install the gem and then run the Passenger installer, by typing the
following commands:
------------------------------------------------------
gem install passenger-x.x.x.gem
passenger-install-apache2-module
------------------------------------------------------
Please follow the instructions given by the installer.
 
==== Installing via a native Linux package ====
 
Please install the native Linux package, e.g.:
------------------------------------------------------
gdebi passenger_x.x.x-i386.deb
------------------------------------------------------
 
Next, you'll need to configure Apache. Run the "installer", as it will tell you
the correct configuration options for Apache:
------------------------------------------------------
passenger-install-apache2-module
------------------------------------------------------
 
NOTE: The installer doesn't actually install anything because it will automatically
detect that Passenger has already been installed. The only thing the installer
will do in this case, is showing the correct Apache configurations.
 
==== Installing via the source tarball ====
 
Extract the tarball to whatever location you prefer. The Passenger files
are to reside in that location permanently. For example, if you would like
Passenger to reside in `/opt/passenger-x.x.x`:
------------------------------------------------------
cd /opt
tar xzvf ~/YourDownloadsFolder/passenger-x.x.x.tar.gz
------------------------------------------------------
 
Next, run the included installer:
------------------------------------------------------
/opt/passenger-x.x.x/bin/passenger-install-apache2-module
------------------------------------------------------
Please follow the instructions given by the installer.
 
IMPORTANT: Please do not remove the 'passenger-x.x.x' folder after
installation. Furthermore, the 'passenger-x.x.x' folder must be accessible by Apache.
 
 
=== Operating system-specific instructions and information ===
 
==== MacOS X ====
 
Ben Ruebenstein has written an excellent
link:http://benr75.com/articles/2008/04/12/setup-mod_rails-phusion-mac-os-x-leopard[tutorial
on installing Phusion Passenger on OS X].
 
==== Ubuntu Linux ====
 
Ben Hughes has written an link:http://www.railsgarden.com/2008/04/12/configurating-passenger-mod_rails-on-slicehost-with-ubuntu-710/[article on installing Passenger on Ubuntu].
 
 
== Deploying a Ruby on Rails application ==
 
Suppose you have a Ruby on Rails application in '/webapps/mycook', and you own
the domain 'www.mycook.com'. You can either deploy your application in the
virtual host's root (i.e. the application will be accessible from the root URL,
'http://www.mycook.com/'), or in a sub URI (i.e. the application will be
accessible from a sub URL, such as 'http://www.mycook.com/railsapplication').
 
NOTE: The default `RAILS_ENV` environment in which deployed Rails applications
are run, is ``production''. You can change this by changing the
<<rails_env,'RailsEnv'>> configuration option.
 
=== Deploying to a virtual host's root ===
 
Add a virtual host entry to your Apache configuration file. The virtual host's
document root must point to your Ruby on Rails application's 'public' folder.
For example:
-------------------------------------------
<VirtualHost *:80>
    ServerName www.mycook.com
    DocumentRoot /webapps/mycook/public
</VirtualHost>
-------------------------------------------
Then restart Apache. The application has now been deployed.
 
[[deploying_to_sub_uri]]
=== Deploying to a sub URI ===
 
Suppose that you already have a virtual host:
 
-------------------------------------------
<VirtualHost *:80>
    ServerName www.phusion.nl
    DocumentRoot /websites/phusion
</VirtualHost>
-------------------------------------------
 
And you want your Ruby on Rails application to be accessible from the URL
'http://www.phusion.nl/rails'.
 
To do this, make a symlink from your Ruby on Rails application's 'public'
folder to a directory in the document root. For example:
-------------------------------------------
ln -s /webapps/mycook/public /websites/phusion/rails
-------------------------------------------
 
Next, add a `RailsBaseURI` option to the virtual host configuration:
-------------------------------------------
<VirtualHost *:80>
    ServerName www.phusion.nl
    DocumentRoot /websites/phusion
    RailsBaseURI /rails # This line has been added.
</VirtualHost>
-------------------------------------------
Then restart Apache. The application has now been deployed.
 
=== Redeploying (restarting the Ruby on Rails application) ===
 
Deploying a new version of a Ruby on Rails application is as simple as
re-uploading the application files, and restarting the application.
 
There are two ways to restart the application:
 
1. By restarting Apache.
2. By creating or modifying the file 'tmp/restart.txt' in the Rails
   application's root folder. Passenger will automatically restart the
   application.
 
For example, to restart our example MyCook application, we type this in the
command line:
-------------------------------------------
touch /webapps/mycook/tmp/restart.txt
-------------------------------------------
 
=== Migrations ===
 
Passenger is not related to Ruby on Rails migrations in any way. To run
migrations on your deployment server, please login to your deployment server
(e.g. with 'ssh') and type `rake db:migrate RAILS_ENV=production' in a shell
console, just like one normally runs migrations.
 
 
== Configuring Passenger ==
 
After installation, Passenger does not need any further configurations.
Nevertheless, the system administrator may be interested in changing
Passenger's behavior. Passenger's Apache module supports the following
configuration options:
 
RailsSpawnServer <filename>::
  The location to the Passenger spawn server. This configuration option is
  essential to Passenger. The correct value is given by the installer,
  and should usually not be changed manually.
+
This option may only occur once, in the global server configuration. If
this option is not given, then Passenger will look for the program
`passenger-spawn-server` in `$PATH`.
 
RailsBaseURI <uri>::
  Used to specify that the given URI is a Rails application. See
  <<deploying_to_sub_uri,Deploying to a sub URI>> for an example.
+
This option may occur multiple times, in the global server configuration or in a
virtual host configuration block.
 
RailsAutoDetect <on|off>::
  Whether Passenger should automatically detect whether a virtual host's
  document root is a Ruby on Rails application. The default is 'on'.
+
This option may occur in the global server configuration or in a virtual host
configuration block.
+
For example, consider the following configuration:
+
-----------------------------
RailsAutoDetect off
<VirtualHost *:80>
    ServerName www.mycook.com
    DocumentRoot /webapps/mycook/public
</VirtualHost>
-----------------------------
+
If one goes to 'http://www.mycook.com/', the visitor will see the contents of
the '/webapps/mycook/public' folder, instead of the output of the Ruby on Rails
application.
+
It is possible to explicitly specify that the host is a Ruby on Rails
application by using the `RailsBaseURI` configuration option:
+
-----------------------------
RailsAutoDetect off
<VirtualHost *:80>
    ServerName www.mycook.com
    DocumentRoot /webapps/mycook/public
    RailsBaseURI /
</VirtualHost>
-----------------------------
 
[[RailsAllowModRewrite]]
RailsAllowModRewrite <on|off>::
  If enabled, Passenger will not override mod_rewrite rules. Please read
  <<conflicting_apache_modules,Conflicting Apache modules>> for details.
+
This option may occur in the global server configuration or in a virtual host
configuration block. The default value is 'off'.
 
RailsRuby <filename>::
  This option allows one to specify the Ruby interpreter to use.
+
This option may only occur once, in the global server configuration.
The default is 'ruby'.
 
[[rails_env]]
RailsEnv <string>::
  This option allows one to specify the default `RAILS_ENV` value.
+
This option may only occur once, in the global server configuration.
The default is 'production'.
+
TIP: Even though it is not possible to specify a different RailsEnv
per virtual host in the Apache configuration file, one can set the
Rails environment by editing `RAILS_ENV=...` in the application's
'config/environment.rb'.
 
RailsMaxPoolSize <integer>::
  The maximum number of Ruby on Rails application instances that may
  be simultaneously active. A larger number results in higher memory usage,
  but improved ability to handle concurrent HTTP clients.
+
The optimal value depends on your system's hardware and the server's average
load. You should experiment with different values. But generally speaking,
the value should be at least equal to the number of CPUs (or CPU cores) that
you have. If your system has 2 GB of RAM, then we recommend a value of '30'.
If your system is a Virtual Private Server (VPS) and has about 256 MB RAM, and
is also running other services such as MySQL, then we recommend a value of '2'.
+
If you find that your server is unable to handle the load on your Rails websites
(i.e. running out of memory) then you should lower this value. (Though if your
sites are really that popular, then you should strongly consider upgrading your
hardware or getting more servers.)
+
This option may only occur once, in the global server configuration.
The default value is '20'.
+
TIP: We strongly recommend you to <<reducing_memory_usage,use Ruby Enterprise
Edition>>. This allows you to reduce your memory usage by about 33%. And it's
not hard to install.
 
RailsPoolIdleTime <integer>::
  The maximum number of seconds that a Ruby on Rails application instance
  may be idle. That is, if an application instance hasn't done anything after
  the given number of seconds, then it will be shutdown in order to conserve
  memory.
+
Decreasing this value means that Rails applications will have to be spawned
more often. Since spawning is a relatively slow operation, some visitors may
notice a small delay when they visit your Rails site. However, it will also
free up resources used by Rails applications more quickly.
+
The optimal value depends on the average time that a visitor spends on a single
Rails web page. We recommend a value of `2 * x`, where `x` is the average
number of seconds that a visitor spends on a single Rails web page. But your
mileage may vary.
+
This option may only occur once, in the global server configuration.
The default value is '120'.
 
[[RailsUserSwitching]]
RailsUserSwitching <on|off>::
  Whether to enable <<user_switching,user switching support>>.
+
This option may only occur once, in the global server configuration.
The default value is 'on'.
 
[[RailsDefaultUser]]
RailsDefaultUser <username>::
  Passenger enables <<user_switching,user switching support>> by default.
  This configuration option allows one to specify which user Rails
  applications must run as, if user switching fails or is disabled.
+
This option may only occur once, in the global server configuration.
The default value is 'nobody'.
 
 
== Troubleshooting ==
 
=== Operating system-specific problems ===
 
==== MacOS X: The installer cannot locate MAMP's Apache ====
 
.Symptoms
*******************************************************************************
The installer finds Apache 2 development headers at `/Applications/MAMP/Library/bin/apxs`.
However, Apache cannot be found. The installer also outputs the following error:
------------------------------------
cannot open /Applications/MAMP/Library/build/config_vars.mk:
No such file or directory at /Applications/MAMP/Library/bin/apxs line 218.
------------------------------------
*******************************************************************************
 
Your MAMP installation seems to be broken. In particular, 'config_vars.mk' is missing.
Please read link:http://forum.mamp.info/viewtopic.php?t=1866[this forum topic] to learn how
to fix this problem.
 
See also link:http://code.google.com/p/phusion-passenger/issues/detail?id=12[this bug report].
 
 
=== Problems during installation ===
 
[[installing_ruby_dev]]
==== Ruby development headers aren't installed ====
 
.Symptoms
*******************************************************************************
Installing Passenger fails because of one of the following errors:
 
- The Passenger installer tells you that the Ruby development headers aren't
  installed.
- The error message ``'no such file to load -- mkmf''' occurs.
- The error message ``'ruby.h: No such file or directory''' occurs.
*******************************************************************************
 
Passenger makes use of a native extension, so the Ruby development headers
must be installed. On most Linux systems, Ruby and the Ruby development headers
are contained in separate packages, so having Ruby installed does not
automatically imply having the development headers installed.
 
Here's how you can install the development headers:
 
Ubuntu/Debian::
  Please type:
+
-----------------------------------------
sudo apt-get install ruby1.8-dev
-----------------------------------------
 
Fedora/CentOS/RHEL::
  Please type:
+
-----------------------------------------
su -c 'yum install ruby-devel'
-----------------------------------------
 
FreeBSD::
  Please install Ruby from 'ports' or with `pkg_add`. If that fails,
  please install Ruby from source.
 
MacOS X::
  Please install Ruby from source.
 
Other operating systems::
  Please consult your operating system's native package database.
  There should be a package containing the Ruby development headers.
  If that fails, please install Ruby from source.
 
NOTE: If you've installed a new Ruby version (i.e. your system now contains
multiple Ruby installations), then you will need to tell Passenger which Ruby
installation you want to use. Please read
<<specifying_ruby_installation,Specifying the correct Ruby installation>>.
 
==== Apache development headers aren't installed ====
 
.Symptoms
*******************************************************************************
Installing Passenger fails because of one of the following errors:
 
- The installer says that the Apache development headers aren't installed.
- The error message ``'httpd.h: No such file or directory''' occurs.
+
(Instead of 'httpd.h', the message might also be 'http_config.h' or something
else similar to 'http_*.h'.)
*******************************************************************************
 
Ubuntu::
  Please type:
+
-----------------------------------------
sudo apt-get install apache2-prefork-dev
-----------------------------------------
 
Debian::
  Please type:
+
-----------------------------------------
sudo apt-get install apache2-dev
-----------------------------------------
 
Fedora/CentOS/RHEL::
  Please type:
+
--------------------------------
su -c 'yum install httpd-devel'
--------------------------------
 
FreeBSD::
  Please install Apache from 'ports' or with `pkg_add`. If that fails,
  please install Apache from source.
 
MacOS X::
  Please install Apache from source.
 
Other operating systems::
  Please consult your operating system's native package database.
  There should be a package containing the Apache development headers.
  If that fails, please install Apache from source.
 
 
==== APR development headers aren't installed ====
 
.Symptoms
*******************************************************************************
Installing Passenger fails because one of the following errors:
 
- The installer tells you that APR development headers aren't installed.
- The error message ``'apr_pools.h: No such file or directory''' occurs.
- The error message ``'apr_strings.h: No such file or directory''' occurs.
*******************************************************************************
 
Ubuntu::
  Please type:
+
-----------------------------------------
sudo apt-get install libapr1-dev
-----------------------------------------
 
Debian::
  Please type:
+
-----------------------------------------
sudo apt-get install libapr1-dev
-----------------------------------------
 
Fedora/CentOS/RHEL::
  Please type:
+
--------------------------------
su -c 'yum install apr-devel'
--------------------------------
 
Other Linux distributions::
  Please consult your distribution's package database. There should be a
  package which provides APR development headers.
 
Other operating systems::
  The APR development are bundled with Apache. If the APR headers aren't,
  then it probably means that they have been removed after Apache's been
  installed. Please reinstall Apache to get back the APR headers.
 
 
==== Passenger is using the wrong Apache during installation ====
 
Please <<specifying_correct_apache_install,Specifying the correct Apache
installation>>, and re-run the Passenger installer.
 
 
==== Passenger is using the wrong Ruby during installation ====
 
Please <<specifying_ruby_installation,Specifying the correct Ruby
installation>>, and re-run the Passenger installer.
 
 
=== Problems after installation ===
 
[TIP]
.The golden tip: read your Apache error logs!
=====================================================
'mod_passenger' will write all errors to the Apache error log. So if
you're experiencing post-installation problems, please look
inside the Apache error logs. It will tell you what exactly went wrong.
=====================================================
 
==== Passenger has been compiled against the wrong Apache installation ====
 
.Symptoms
*******************************************************************************
Apache crashes during startup (after being daemonized). The Apache error log
says ``'seg fault or similar nasty error detected in the parent process'''.
*******************************************************************************
 
This problem is most likely to occur on MacOS X. Most OS X users have multiple
Apache installations on their system.
 
To solve this problem, please <<specifying_correct_apache_install,specify the
correct Apache installation>>, and <<install_passenger,reinstall Passenger>>.
 
==== I get a "304 Forbidden" error ====
 
See next subsection.
 
==== Static assets such as images and stylesheets aren't being displayed ====
 
Static assets are accelerated, i.e. they are served directly by Apache and do not
go through the Rails stack. There are two reasons why Apache doesn't serve static
assets correctly:
 
1. Your Apache configuration is too strict, and does not allow HTTP clients to
   access static assets. This can be achieved with an `Allow from all` directive
   in the correct place. For example:
+
-----------------------------------------
<Directory "/webapps/mycook/public">
   Options FollowSymLinks
   AllowOverride None
   Order allow,deny
   Allow from all
</Directory>
-----------------------------------------
+
See also link:http://groups.google.com/group/phusion-passenger/browse_thread/thread/9699a639a87f85f4/b9d71a03bf2670a5[this discussion].
 
2. The Apache process doesn't have permission to access your Rails application's folder.
   Please make sure that the Rails application's folder, as well as all of its parent folders,
   have the correct permissions and/or ownerships.
 
==== The Apache error log says that the spawn manager script does not exist, or that it does not have permission to execute it ====
 
If you are sure that the RailsSpawnServer configuration option is set correctly,
then this problem is most likely caused by the fact that you're running Apache
with SELinux. On Fedora, CentOS and RedHat Enterprise Linux, Apache is locked
down by SELinux policies.
 
To solve this problem, you must set some permissions on the Passenger files and
folders, so that Apache can access them.
 
- If you've installed Passenger via a gem, then run this command to determine
  Passenger's root folder:
+
------------------------------------------------------------------
passenger-config --root
------------------------------------------------------------------
+
Next, run the following command:
+
------------------------------------------------------------------
chcon -R -h -t httpd_sys_content_t /path-to-passenger-root
------------------------------------------------------------------
+
where '/path-to-passenger-root' should be replaced with whatever
`passenger-config --root` printed.
 
- If you've installed Passenger via the source tarball, then run the following
  command:
+
------------------------------------------------------------------
chcon -R -h -t httpd_sys_content_t /path/to/passenger/folder
------------------------------------------------------------------
 
Once the permissions are fixed, restart Apache.
 
==== The Rails application reports that it's unable to start because of a permission error ====
 
Please check whether your Rails application's folder has the correct
permissions. By default, Rails applications are started as the owner of the
file 'config/environment.rb', except if the file is owned by root. If the
file is owned by root, then the Rails application will be started as 'nobody'
(or as the user specify by <<RailsDefaultUser,RailsDefaultUser>>, if that's
specified).
 
Please read <<user_switching,User switching (security)>> for details.
 
==== My Rails application's log file is not being written to ====
 
There are a couple things that you should be aware of:
 
- By default, Passenger runs Rails applications in 'production' mode, so please
  be sure to check 'production.log' instead of 'development.log'. See
  <<RailsEnv,RailsEnv>> for configuration.
- By default, Passenger runs Rails applications as the owner of 'environment.rb'.
  So the log file can only be written to if that user has write permission to the
  log file. Please 'chmod' or 'chown' your log file accordingly.
+
See <<User_switching,User switching (security)>> for details.
 
If you're using a RedHat-derived Linux distribution (such as Fedora or CentOS)
then it is link:http://code.google.com/p/phusion-passenger/issues/detail?id=4[possible
that SELinux is interfering]. RedHat's SELinux policy only allows Apache to read/write
directories that have the 'httpd_sys_content_t' security context. Please run the
following command to give your Rails application folder that context:
 
-----------------------------------------------------------
chcon -R -h -t httpd_sys_content_t /path/to/your/rails/app
-----------------------------------------------------------
 
[[conflicting_apache_modules]]
=== Conflicting Apache modules ===
 
==== mod_rewrite and mod_alias ====
 
Passenger conflicts with 'mod_rewrite' and 'mod_alias'. Those modules may be
installed and loaded together with 'mod_passenger', and they will work fine
outside virtual hosts that contain a Rails application, but we recommend you
not to use their features inside virtual hosts that contain a Rails
application.
 
By default, Passenger will override mod_rewrite rules on Rails hosts. This is
because the default .htaccess, as provided by Ruby on Rails, redirects all
requests to `dispatch.cgi' using mod_rewrite. This is a CGI application which
loads the entire Ruby on Rails framework for every request, and thus is very
slow. If we do not override mod_rewrite, then Ruby on Rails apps will be slow
on Passenger by default -- but we want a good out-of-the-box experience.
 
Furthermore, the primary reason why people use mod_rewrite with Rails
applications, is to accelerate page caching. Passenger supports page caching
out-of-the-box, without mod_rewrite.
 
It is not fully understood how mod_alias conflicts with Passenger, but we
recommend you not to use it on Rails virtual hosts. mod_alias rules can result
in surprising problems.
 
If you really want to use mod_rewrite on Rails virtual hosts, then please set
the <<RailsAllowModRewrite,RailsAllowModRewrite>> configuration option. But
please note that you will have to delete Rails applications' default .htaccess
file, or add rewrite rules to negate its effects.
 
==== mod_userdir ====
 
'mod_userdir' is not compatible with Phusion Passenger at the moment.
 
==== VirtualDocumentRoot ====
 
VirtualDocumentRoot is not compatible with Phusion Passenger at the moment.
 
 
== Tips and notes ==
 
[[user_switching]]
=== User switching (security) ===
 
There is a problem that plagues most PHP web host, namely the fact that all PHP
applications are run in the same user context as the web server. So for
example, Joe's PHP application will be able to read Jane's PHP application's
passwords. This is obviously undesirable on many servers.
 
Passenger solves this problem by implementing 'user switching'. A Rails
application is started as the owner of the file 'config/environment.rb'. So if
'/home/webapps/foo/config/environment.rb' is owned by 'joe', then Passenger
will launch the corresponding Rails application as 'joe' as well.
 
This behavior is the default, and you don't need to configure anything. But
there are things that you should keep in mind:
 
- The owner of 'environment.rb' must have read access to the Rails application's
  folder, and read/write access to the Rails application's 'logs' folder.
- This feature is only available if Apache is started by 'root'. This is the
  case on most Apache installations.
- Under no circumstances will Rails applications be run as 'root'. If
  'environment.rb' is owned as root or by an unknown user, then the Rails
  application will run as the user specified by
  <<RailsDefaultUser,RailsDefaultUser>>.
 
User switching can be disabled with the
<<RailsUserSwitching,RailsUserSwitching>> option.
 
 
[[reducing_memory_usage]]
=== Reducing memory consumption of Ruby on Rails apps by 33% ===
 
Is it possible to reduce memory consumption of your Rails apps by 33% on average,
by using http://www.rubyenterpriseedition.com/[Ruby Enterprise Edition].
Please visit the website for details.
 
=== Moving Passenger to a different directory ===
 
It is possible to relocate the Passenger files to a different directory. It
involves two steps:
 
1. Moving the directory.
2. Updating the ``RailsSpawnServer'' configuration option in Apache.
 
For example, if Passenger is located in '/opt/passenger/', and you'd like to
move it to '/usr/local/passenger/', then do this:
 
1. Run the following command:
+
------------------------------------
mv /opt/passenger /usr/local/passenger
------------------------------------
2. Edit your Apache configuration file, and set:
+
------------------------------------
RailsSpawnServer /usr/local/passenger/bin/passenger-spawn-server
------------------------------------
 
=== Installing multiple Ruby on Rails versions ===
 
Each Ruby on Rails applications that are going to be deployed may require a
specific Ruby on Rails version. You can install a specific version with
this command:
-----------------------------
gem install rails -v X.X.X
-----------------------------
where 'X.X.X' is the version number of Ruby on Rails.
 
All of these versions will exist in parallel, and will not conflict with each
other. Passenger will automatically make use of the correct version.
 
=== X-Sendfile support ===
 
Passenger does not provide X-Sendfile support by itself. Please install
link:http://tn123.ath.cx/mod_xsendfile/[mod_xsendfile] for X-Sendfile support.
 
 
== Appendix A: About this document ==
 
The text of this document is licensed under the
link:http://creativecommons.org/licenses/by-sa/3.0/[Creative Commons
Attribution-Share Alike 3.0 Unported License].
 
image:images/by_sa.png[link="http://creativecommons.org/licenses/by-sa/3.0/"]
 
Passenger is brought to you by Phusion.
 
image:images/phusion_banner.png[link="http://www.phusion.nl/"]