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 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.5.2" />
<title>Phusion Passenger users guide</title>
<style type="text/css">
/* Debug borders */
p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
/*
border: 1px solid red;
*/
}
body {
margin: 1em 5% 1em 5%;
}
a {
color: blue;
text-decoration: underline;
}
a:visited {
color: fuchsia;
}
em {
font-style: italic;
color: navy;
}
strong {
font-weight: bold;
color: #083194;
}
tt {
color: navy;
}
h1, h2, h3, h4, h5, h6 {
color: #527bbd;
font-family: sans-serif;
margin-top: 1.2em;
margin-bottom: 0.5em;
line-height: 1.3;
}
h1, h2, h3 {
border-bottom: 2px solid silver;
}
h2 {
padding-top: 0.5em;
}
h3 {
float: left;
}
h3 + * {
clear: left;
}
div.sectionbody {
font-family: serif;
margin-left: 0;
}
hr {
border: 1px solid silver;
}
p {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
ul, ol, li > p {
margin-top: 0;
}
pre {
padding: 0;
margin: 0;
}
span#author {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
font-size: 1.1em;
}
span#email {
}
span#revnumber, span#revdate, span#revremark {
font-family: sans-serif;
}
div#footer {
font-family: sans-serif;
font-size: small;
border-top: 2px solid silver;
padding-top: 0.5em;
margin-top: 4.0em;
}
div#footer-text {
float: left;
padding-bottom: 0.5em;
}
div#footer-badges {
float: right;
padding-bottom: 0.5em;
}
div#preamble {
margin-top: 1.5em;
margin-bottom: 1.5em;
}
div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
margin-top: 1.0em;
margin-bottom: 1.5em;
}
div.admonitionblock {
margin-top: 2.0em;
margin-bottom: 2.0em;
margin-right: 10%;
color: #606060;
}
div.content { /* Block element content. */
padding: 0;
}
/* Block element titles. */
div.title, caption.title {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
text-align: left;
margin-top: 1.0em;
margin-bottom: 0.5em;
}
div.title + * {
margin-top: 0;
}
td div.title:first-child {
margin-top: 0.0em;
}
div.content div.title:first-child {
margin-top: 0.0em;
}
div.content + div.title {
margin-top: 0.0em;
}
div.sidebarblock > div.content {
background: #ffffee;
border: 1px solid silver;
padding: 0.5em;
}
div.listingblock > div.content {
border: 1px solid silver;
background: #f4f4f4;
padding: 0.5em;
}
div.quoteblock, div.verseblock {
padding-left: 1.0em;
margin-left: 1.0em;
margin-right: 10%;
border-left: 5px solid #dddddd;
color: #777777;
}
div.quoteblock > div.attribution {
padding-top: 0.5em;
text-align: right;
}
div.verseblock > div.content {
white-space: pre;
}
div.verseblock > div.attribution {
padding-top: 0.75em;
text-align: left;
}
/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
div.verseblock + div.attribution {
text-align: left;
}
div.admonitionblock .icon {
vertical-align: top;
font-size: 1.1em;
font-weight: bold;
text-decoration: underline;
color: #527bbd;
padding-right: 0.5em;
}
div.admonitionblock td.content {
padding-left: 0.5em;
border-left: 3px solid #dddddd;
}
div.exampleblock > div.content {
border-left: 3px solid #dddddd;
padding-left: 0.5em;
}
div.imageblock div.content { padding-left: 0; }
span.image img { border-style: none; }
a.image:visited { color: white; }
dl {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
dt {
margin-top: 0.5em;
margin-bottom: 0;
font-style: normal;
color: navy;
}
dd > *:first-child {
margin-top: 0.1em;
}
ul, ol {
list-style-position: outside;
}
ol.arabic {
list-style-type: decimal;
}
ol.loweralpha {
list-style-type: lower-alpha;
}
ol.upperalpha {
list-style-type: upper-alpha;
}
ol.lowerroman {
list-style-type: lower-roman;
}
ol.upperroman {
list-style-type: upper-roman;
}
div.compact ul, div.compact ol,
div.compact p, div.compact p,
div.compact div, div.compact div {
margin-top: 0.1em;
margin-bottom: 0.1em;
}
div.tableblock > table {
border: 3px solid #527bbd;
}
thead, p.table.header {
font-family: sans-serif;
font-weight: bold;
}
tfoot {
font-weight: bold;
}
td > div.verse {
white-space: pre;
}
p.table {
margin-top: 0;
}
/* Because the table frame attribute is overriden by CSS in most browsers. */
div.tableblock > table[frame="void"] {
border-style: none;
}
div.tableblock > table[frame="hsides"] {
border-left-style: none;
border-right-style: none;
}
div.tableblock > table[frame="vsides"] {
border-top-style: none;
border-bottom-style: none;
}
div.hdlist {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
div.hdlist tr {
padding-bottom: 15px;
}
dt.hdlist1.strong, td.hdlist1.strong {
font-weight: bold;
}
td.hdlist1 {
vertical-align: top;
font-style: normal;
padding-right: 0.8em;
color: navy;
}
td.hdlist2 {
vertical-align: top;
}
div.hdlist.compact tr {
margin: 0;
padding-bottom: 0;
}
.comment {
background: yellow;
}
.footnote, .footnoteref {
font-size: 0.8em;
}
span.footnote, span.footnoteref {
vertical-align: super;
}
#footnotes {
margin: 20px 0 20px 0;
padding: 7px 0 0 0;
}
#footnotes div.footnote {
margin: 0 0 5px 0;
}
#footnotes hr {
border: none;
border-top: 1px solid silver;
height: 1px;
text-align: left;
margin-left: 0;
width: 20%;
min-width: 100px;
}
@media print {
div#footer-badges { display: none; }
}
div#toc {
margin-bottom: 2.5em;
}
div#toctitle {
color: #527bbd;
font-family: sans-serif;
font-size: 1.1em;
font-weight: bold;
margin-top: 1.0em;
margin-bottom: 0.1em;
}
div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
margin-top: 0;
margin-bottom: 0;
}
div.toclevel2 {
margin-left: 2em;
font-size: 0.9em;
}
div.toclevel3 {
margin-left: 4em;
font-size: 0.9em;
}
div.toclevel4 {
margin-left: 6em;
font-size: 0.9em;
}
/* Workarounds for IE6's broken and incomplete CSS2. */
div.sidebar-content {
background: #ffffee;
border: 1px solid silver;
padding: 0.5em;
}
div.sidebar-title, div.image-title {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
margin-top: 0.0em;
margin-bottom: 0.5em;
}
div.listingblock div.content {
border: 1px solid silver;
background: #f4f4f4;
padding: 0.5em;
}
div.quoteblock-attribution {
padding-top: 0.5em;
text-align: right;
}
div.verseblock-content {
white-space: pre;
}
div.verseblock-attribution {
padding-top: 0.75em;
text-align: left;
}
div.exampleblock-content {
border-left: 3px solid #dddddd;
padding-left: 0.5em;
}
/* IE6 sets dynamically generated links as visited. */
div#toc a:visited { color: blue; }
</style>
<script type="text/javascript">
/*<+'])');
// Function that scans the DOM tree for header elements (the DOM2
// nodeIterator API would be a better technique but not supported by all
// browsers).
var iterate = function (el) {
for (var i = el.firstChild; i != null; i = i.nextSibling) {
if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
var mo = re.exec(i.tagName);
if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
}
iterate(i);
}
}
}
iterate(el);
return result;
}
var toc = document.getElementById("toc");
var entries = tocEntries(document.getElementById("content"), toclevels);
for (var i = 0; i < entries.length; ++i) {
var entry = entries[i];
if (entry.element.id == "")
entry.element.id = "_toc_" + i;
var a = document.createElement("a");
a.href = "#" + entry.element.id;
a.appendChild(document.createTextNode(entry.text));
var div = document.createElement("div");
div.appendChild(a);
div.className = "toclevel" + entry.toclevel;
toc.appendChild(div);
}
if (entries.length == 0)
toc.parentNode.removeChild(toc);
},
/////////////////////////////////////////////////////////////////////
// Footnotes generator
/////////////////////////////////////////////////////////////////////
/* Based on footnote generation code from:
* http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
*/
footnotes: function () {
var cont = document.getElementById("content");
var noteholder = document.getElementById("footnotes");
var spans = cont.getElementsByTagName("span");
var refs = {};
var n = 0;
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnote") {
n++;
// Use [\s\S] in place of . so multi-line matches work.
// Because JavaScript has no s (dotall) regex flag.
note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
noteholder.innerHTML +=
"<div class='footnote' id='_footnote_" + n + "'>" +
"<a href='#_footnoteref_" + n + "' title='Return to text'>" +
n + "</a>. " + note + "</div>";
spans[i].innerHTML =
"[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
var id =spans[i].getAttribute("id");
if (id != null) refs["#"+id] = n;
}
}
if (n == 0)
noteholder.parentNode.removeChild(noteholder);
else {
// Process footnoterefs.
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnoteref") {
var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
href = href.match(/#.*/)[0]; // Because IE return full URL.
n = refs[href];
spans[i].innerHTML =
"[<a href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
}
}
}
}
}
/*]]>*/
</script>
</head>
<body>
<div id="header">
<h1>Phusion Passenger users guide</h1>
<div id="toc">
<div id="toctitle">Table of Contents</div>
<noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p><span class="image">
<a class="image" href="http://www.phusion.nl/">
<img src="images/phusion_banner.png" alt="images/phusion_banner.png" />
</a>
</span></p></div>
<div class="paragraph"><p>Phusion Passenger is an Apache module, which makes deploying Ruby and 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, while at the
same time providing enough flexibility.</p></div>
<div class="paragraph"><p>This users guide will teach you:</p></div>
<div class="ulist"><ul>
<li>
<p>
How to install Phusion Passenger.
</p>
</li>
<li>
<p>
How to configure Phusion Passenger.
</p>
</li>
<li>
<p>
How to deploy a Ruby on Rails application.
</p>
</li>
<li>
<p>
How to deploy a <a href="http://rack.rubyforge.org/">Rack</a>-based Ruby application.
</p>
</li>
<li>
<p>
How to solve common problems.
</p>
</li>
</ul></div>
<div class="paragraph"><p>This guide assumes that the reader is somewhat familiar with Apache and with
using the commandline.</p></div>
</div>
</div>
<h2 id="_supported_operating_systems">1. Supported operating systems</h2>
<div class="sectionbody">
<div class="paragraph"><p>Phusion Passenger works on any POSIX-compliant operating system. In other
words: practically any operating system on earth, except Microsoft Windows.</p></div>
<div class="paragraph"><p>Phusion Passenger is confirmed on a large number of operating systems and Linux
distributions, including, but not limited to, Ubuntu, Debian, CentOS/Fedora/RHEL,
Gentoo, Mac OS X, FreeBSD and Solaris. Both 32-bit and 64-bit platforms are supported.</p></div>
<div class="paragraph"><p>The only POSIX-compliant operating system on which Phusion Passenger for Apache is
known not to work at this time, is OpenBSD. Please use Phusion Passenger for Nginx
instead.</p></div>
<div class="paragraph"><p>If Phusion Passenger does not work on your platform then please
<a href="http://code.google.com/p/phusion-passenger/issues/list">report a bug</a>
or
<a href="http://groups.google.com/group/phusion-passenger">join our discussion list</a>.</p></div>
</div>
<h2 id="_installing_upgrading_and_uninstalling_phusion_passenger">2. Installing, upgrading and uninstalling Phusion Passenger</h2>
<div class="sectionbody">
<h3 id="_generic_installation_instructions">2.1. Generic installation instructions</h3><div style="clear:left"></div>
<h4 id="install_passenger">2.1.1. Overview of installation methods</h4>
<div class="paragraph"><p>There are three ways to install Phusion Passenger:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
By installing the Phusion Passenger gem, as instructed on the
<a href="http://www.modrails.com/install.html">“Install” page on the Phusion
Passenger website</a>.
</p>
</li>
<li>
<p>
By downloading the source tarball from the Phusion Passenger website
(<em>passenger-x.x.x.tar.gz</em>).
</p>
</li>
<li>
<p>
By installing a native Linux package (e.g. Debian package).
</p>
</li>
</ol></div>
<div class="paragraph"><p>The following sections will explain each installation method. Please read the
section for the installation method that you prefer. In our opinion, installing
the gem or the native package is easiest. For these two installation methods,
Phusion Passenger provides an easy-to-use installer.</p></div>
<h4 id="_preparation_gem_and_source_tarball_only">2.1.2. Preparation (gem and source tarball only)</h4>
<div class="paragraph"><p>If you want to install Phusion Passenger via the gem or the source tarball,
then some preparations might be required. You can skip this subsection if
you’re installing Phusion Passenger via a native Linux package, because no
compilation is necessary.</p></div>
<h5 id="_switching_to_a_root_command_prompt">Switching to a root command prompt</h5>
<div class="paragraph"><p>Before installing, you will probably need to switch to the <tt>root</tt> user first.
When you install Phusion Passenger via a gem or a source tarball, some Phusion
Passenger files have to be compiled, which requires write access to the
directory in which the Phusion Passenger files are located. On Unix systems,
the root user is the user who has write access to the entire system. So unless
you know that your normal user account has write access to the Phusion Passenger
directory, you should switch to root before installing Phusion Passenger.</p></div>
<div class="paragraph"><p>You can switch to root by typing the following command:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>sudo -s</tt></pre>
</div></div>
<div class="paragraph"><p>This will open a command prompt as the root user, from which you can proceed
with installing Phusion Passenger.</p></div>
<div class="paragraph"><p>If your system does not have <em>sudo</em> installed, please type the following command instead, which should do the same thing:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>su</tt></pre>
</div></div>
<h5 id="specifying_correct_apache_install">Specifying the correct Apache installation</h5>
<div class="paragraph"><p>The Phusion Passenger installer will attempt to automatically detect Apache,
and compile Phusion Passenger against that Apache version. It does this by
looking for the <tt>apxs</tt> or <tt>apxs2</tt> command in the PATH environment variable.
Apxs is an integral part of any Apache installation.</p></div>
<div class="paragraph"><p>However, some systems have multiple Apache installations. This is likely
the case on MacOS X: the OS ships with Apache, but users tend to install
another Apache version seperately, e.g. via MacPorts. If your system has
multiple Apache installations, then you will need to tell the Phusion Passenger
installer which one to use. It is very important that you specify the
correct Apache installation, because if you load Phusion Passenger in an
Apache installation that it wasn’t compiled against, then it will likely
crash.</p></div>
<div class="paragraph"><p>On yet other systems, Apache is installed in a non-standard location,
preventing the Phusion Passenger installer from detecting Apache. This
is most likely the case on systems on which Apache was installed by hand
from source, i.e. as opposed to installed through the system’s native
package manager. If this is the case, then you will also have to tell
the installer where it can find Apache.</p></div>
<div class="paragraph"><p>To do so, set the <tt>APXS2</tt> environment variable to the full path of the
correct <tt>apxs</tt> or <tt>apxs2</tt> command. Suppose that you want to use the Apache
installation in <em>/opt/apache2</em>. Then, assuming that the corresponding
<tt>apxs</tt> program’s path is <em>/opt/apache2/bin/apxs</em>, type:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>export APXS2=/opt/apache2/bin/apxs</tt></pre>
</div></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">On some systems, the <tt>apxs</tt> program might be called <tt>apxs2</tt>, and it might
be located in the <tt>sbin</tt> folder instead of the <tt>bin</tt> folder.</td>
</tr></table>
</div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">
<div class="title">Environment variables and <em>sudo</em></div>By default, the <em>sudo</em> command will erase any environment variables that it
doesn’t recognize, prior to executing the given command. So if you set APXS2 as a
normal user, then run <tt>sudo passenger-install-apache2-module</tt> (which is the command
for the Phusion Passenger installer), then the installer will not receive the
environment variable value that you set. To solve this problem, please become root
prior to setting any environment variables, as described in the previous subsection.</td>
</tr></table>
</div>
<h5 id="specifying_ruby_installation">Specifying the correct Ruby installation</h5>
<div class="paragraph"><p>If your system has multiple Ruby installations — which is likely the case on
MacOS X, or if you’ve also installed
<a href="http://www.rubyenterpriseedition.com">Ruby Enterprise Edition</a> — then you
will need to tell the operating system which Ruby installation to use, prior to
running the Phusion Passenger installer. If you only have one Ruby installation
(the case on most Linux systems), then you can skip this section because Phusion
Passenger will automatically detect it.</p></div>
<div class="paragraph"><p>To specify a Ruby installation, prepend your Ruby installation’s <tt>bin</tt>
directory to the <tt>PATH</tt> environment variable. For example, if you have the
following Ruby installations:</p></div>
<div class="ulist"><ul>
<li>
<p>
/usr/bin/ruby
</p>
</li>
<li>
<p>
/opt/myruby/bin/ruby
</p>
</li>
</ul></div>
<div class="paragraph"><p>and you want to use the latter, then type:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>export PATH=/opt/myruby/bin:$PATH</tt></pre>
</div></div>
<h4 id="_installing_via_the_gem">2.1.3. Installing via the gem</h4>
<div class="paragraph"><p>Please install the gem and then run the Phusion Passenger installer, by typing the
following commands:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>gem install passenger-x.x.x.gem
passenger-install-apache2-module</tt></pre>
</div></div>
<div class="paragraph"><p>Please follow the instructions given by the installer.</p></div>
<h4 id="_installing_via_the_source_tarball">2.1.4. Installing via the source tarball</h4>
<div class="paragraph"><p>Extract the tarball to whatever location you prefer. <strong>The Phusion Passenger files
are to reside in that location permanently.</strong> For example, if you would like
Phusion Passenger to reside in <tt>/opt/passenger-x.x.x</tt>:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>cd /opt
tar xzvf ~/YourDownloadsFolder/passenger-x.x.x.tar.gz</tt></pre>
</div></div>
<div class="paragraph"><p>Next, run the included installer:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>/opt/passenger-x.x.x/bin/passenger-install-apache2-module</tt></pre>
</div></div>
<div class="paragraph"><p>Please follow the instructions given by the installer.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/important.png" alt="Important" />
</td>
<td class="content">Please do not remove the <em>passenger-x.x.x</em> folder after
installation. Furthermore, the <em>passenger-x.x.x</em> folder must be accessible by Apache.</td>
</tr></table>
</div>
<h4 id="_installing_via_a_native_linux_package">2.1.5. Installing via a native Linux package</h4>
<div class="paragraph"><p>John Leach from Brightbox has kindly provided an Ubuntu Hardy package for Phusion Passenger. The package is available from the <a href="http://apt.brightbox.net">Brightbox repository</a>.</p></div>
<div class="paragraph"><p>Please install the native Linux package, e.g.:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>sudo sh -c 'echo "deb http://apt.brightbox.net hardy main" > /etc/apt/sources.list.d/brightbox.list'
sudo sh -c 'wget -q -O - http://apt.brightbox.net/release.asc | apt-key add -'
sudo apt-get update
sudo apt-get install libapache2-mod-passenger</tt></pre>
</div></div>
<h4 id="_what_does_the_installer_do">2.1.6. What does the installer do?</h4>
<div class="paragraph"><p>Although we call it an “installer”, it doesn’t actually install anything.
The installer checks whether all required dependencies are installed,
compiles Phusion Passenger for you, and tells you how to modify the Apache
configuration file, but it doesn’t copy any files around.</p></div>
<div class="paragraph"><p><tt>passenger-install-apache2-module</tt> is actually just a user-friendly frontend
around the command <tt>rake apache2</tt>, which performs the actual compilation of
Phusion Passenger.</p></div>
<h3 id="_operating_system_specific_instructions_and_information">2.2. Operating system-specific instructions and information</h3><div style="clear:left"></div>
<h4 id="_macos_x">2.2.1. MacOS X</h4>
<div class="paragraph"><p>Ben Ruebenstein has written an excellent
<a href="http://benr75.com/articles/2008/04/12/setup-mod_rails-phusion-mac-os-x-leopard">tutorial
on installing Phusion Passenger on OS X</a>.</p></div>
<h4 id="_ubuntu_linux">2.2.2. Ubuntu Linux</h4>
<div class="paragraph"><p>Ben Hughes has written an <a href="http://www.railsgarden.com/2008/04/12/configurating-passenger-mod_rails-on-slicehost-with-ubuntu-710/">article on installing Phusion Passenger on Ubuntu</a>.</p></div>
<h4 id="_opensolaris">2.2.3. OpenSolaris</h4>
<div class="paragraph"><p>J Aaron Farr has written a <a href="http://cubiclemuses.com/cm/articles/2009/04/09/rails-passenger-open-solaris-ec2/">guide</a>
about setting up Ruby on Rails and Phusion Passenger on OpenSolaris and EC2.</p></div>
<h3 id="_upgrading_or_downgrading_phusion_passenger">2.3. Upgrading or downgrading Phusion Passenger</h3><div style="clear:left"></div>
<h4 id="_via_a_gem_or_a_source_tarball">2.3.1. Via a gem or a source tarball</h4>
<div class="paragraph"><p>To ugrade or downgrade Phusion Passenger via the gem or the source tarball, install the newer
or older version as you normally would; that is, install the gem or unpack the tarball, and
run <tt>passenger-install-apache2-module</tt>. Eventually <tt>passenger-install-apache2-module</tt> will tell
you to copy & paste some settings into the Apache configuration file; something that looks along
the lines of:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>LoadModule passenger_module ...
PassengerRoot ...
PassengerRuby ...</tt></pre>
</div></div>
<div class="paragraph"><p>Because you already have Phusion Passenger installed, you already have the same settings
in your Apache configuration file, just with different values. Replace the old settings with
the new ones that the installer outputs.</p></div>
<div class="paragraph"><p>When you’re done, restart Apache.</p></div>
<h4 id="_via_a_native_linux_package">2.3.2. Via a native Linux package</h4>
<div class="paragraph"><p>There are no special instructions required to upgrade or downgrade Phusion Passenger
via a native Linux package.</p></div>
<h3 id="_unloading_disabling_phusion_passenger_from_apache_without_uninstalling_it">2.4. Unloading (disabling) Phusion Passenger from Apache without uninstalling it</h3><div style="clear:left"></div>
<div class="paragraph"><p>You can temporarily unload (disable) Phusion Passenger from Apache, without
uninstalling the Phusion Passenger files, so that Apache behaves as if Phusion
Passenger was never installed in the first place. This might be useful to you if,
for example, you seem to be experiencing a problem caused by Phusion Passenger,
but you want to make sure whether that’s actually the case, without having
to through the hassle of uninstalling Phusion Passenger completely.</p></div>
<div class="paragraph"><p>To unload Phusion Passenger from Apache, edit your Apache configuration file(s)
and comment out:</p></div>
<div class="ulist"><ul>
<li>
<p>
all Phusion Passenger configuration directives.
</p>
</li>
<li>
<p>
the <em>LoadModule passenger_module</em> directive.
</p>
</li>
</ul></div>
<div class="paragraph"><p>For example, if your configuration file looks like this…</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Listen *:80
NameVirtualHosts *:80
....
LoadModule passenger_module /somewhere/passenger-x.x.x/ext/apache2/mod_passenger.so
PassengerRuby /usr/bin/ruby
PassengerRoot /somewhere/passenger/x.x.x
PassengerMaxPoolSize 10
<VirtualHost *:80>
ServerName www.foo.com
DocumentRoot /webapps/foo/public
RailsBaseURI /rails
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>…then comment out the relevant directives, so that it looks like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Listen *:80
NameVirtualHosts *:80
....
# LoadModule passenger_module /somewhere/passenger-x.x.x/ext/apache2/mod_passenger.so
# PassengerRuby /usr/bin/ruby
# PassengerRoot /somewhere/passenger/x.x.x
# PassengerMaxPoolSize 10
<VirtualHost *:80>
ServerName www.foo.com
DocumentRoot /webapps/foo/public
# RailsBaseURI /rails
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>After you’ve done this, save the file and restart Apache.</p></div>
<h3 id="_uninstalling_phusion_passenger">2.5. Uninstalling Phusion Passenger</h3><div style="clear:left"></div>
<div class="paragraph"><p>To uninstall Phusion Passenger, please first remove all Phusion Passenger
configuration directives from your Apache configuration file(s). After you’ve
done this, you need to remove the Phusion Passenger files.</p></div>
<div class="ulist"><ul>
<li>
<p>
If you installed Phusion Passenger via a gem, then type <tt>gem uninstall passenger</tt>.
You might have to run this as root.
</p>
</li>
<li>
<p>
If you installed Phusion Passenger via a source tarball, then remove the directory
in which you placed the extracted Phusion Passenger files. This directory is the
same as the one pointed to the by <em>PassengerRoot</em> configuration directive.
</p>
</li>
<li>
<p>
If you installed Phusion Passenger via a Debian package, then remove type
<tt>sudo apt-get remove libapache2-mod-passenger</tt>.
</p>
</li>
</ul></div>
</div>
<h2 id="_deploying_a_ruby_on_rails_application">3. Deploying a Ruby on Rails application</h2>
<div class="sectionbody">
<div class="paragraph"><p>Suppose you have a Ruby on Rails application in <em>/webapps/mycook</em>, and you own
the domain <em>www.mycook.com</em>. You can either deploy your application to the
virtual host’s root (i.e. the application will be accessible from the root URL,
<em>http://www.mycook.com/</em>), or in a sub URI (i.e. the application will be
accessible from a sub URL, such as <em>http://www.mycook.com/railsapplication</em>).</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">The default <tt>RAILS_ENV</tt> environment in which deployed Rails applications
are run, is “production”. You can change this by changing the
<a href="#rails_env"><em>RailsEnv</em></a> configuration option.</td>
</tr></table>
</div>
<h3 id="_deploying_to_a_virtual_host_8217_s_root">3.1. Deploying to a virtual host’s root</h3><div style="clear:left"></div>
<div class="paragraph"><p>Add a virtual host entry to your Apache configuration file. Make sure that the
following conditions are met:</p></div>
<div class="ulist"><ul>
<li>
<p>
The virtual host’s document root must point to your Ruby on Rails application’s
<em>public</em> folder.
</p>
</li>
<li>
<p>
The Apache per-directory permissions must allow access to this folder.
</p>
</li>
<li>
<p>
MultiViews must be disabled for this folder.
</p>
</li>
</ul></div>
<div class="paragraph"><p>For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.mycook.com
DocumentRoot /webapps/mycook/public
<Directory /webapps/mycook/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>You may also need to tweak your file/folder permissions. Make sure that the
following folders are readable and executable by Apache:</p></div>
<div class="ulist"><ul>
<li>
<p>
this <em>public</em> folder.
</p>
</li>
<li>
<p>
the application’s <em>config</em> folder.
</p>
</li>
<li>
<p>
all parent folders. That is, /webapps/mycook and /webapps must also be readable and executable by Apache.
</p>
</li>
</ul></div>
<div class="paragraph"><p>Then restart Apache. The application has now been deployed.</p></div>
<h3 id="deploying_rails_to_sub_uri">3.2. Deploying to a sub URI</h3><div style="clear:left"></div>
<div class="paragraph"><p>Suppose that you already have a virtual host:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>And you want your Ruby on Rails application to be accessible from the URL
<em>http://www.phusion.nl/rails</em>.</p></div>
<div class="paragraph"><p>To do this, make a symlink from your Ruby on Rails application’s <em>public</em>
folder to a directory in the document root. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>ln -s /webapps/mycook/public /websites/phusion/rails</tt></pre>
</div></div>
<div class="paragraph"><p>Next, add a <a href="#RailsBaseURI">RailsBaseURI</a> option to the virtual host configuration,
and also make sure that:</p></div>
<div class="ulist"><ul>
<li>
<p>
The Apache per-directory permissions allow access to this folder.
</p>
</li>
<li>
<p>
MultiViews is disabled for this folder.
</p>
</li>
</ul></div>
<div class="paragraph"><p>For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
RailsBaseURI /rails # <-- These lines have
<Directory /websites/phusion/rails> # <-- been added.
Options -MultiViews # <--
</Directory> # <--
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>Then restart Apache. The application has now been deployed.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">If you’re deploying to a sub-URI then please make sure that your view
templates correctly handles references to sub-URI static assets! Otherwise
you may find broken links to images, CSS files, JavaScripts, etc. Please read
<a href="#sub_uri_deployment_uri_fix">How to fix broken images/CSS/JavaScript URIs in sub-URI deployments</a>
for more information.</td>
</tr></table>
</div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">
<div class="paragraph"><p>You can deploy multiple Rails applications under a virtual host, by specifying
<a href="#RailsBaseURI">RailsBaseURI</a> multiple times. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
....
RailsBaseURI /app1
RailsBaseURI /app2
RailsBaseURI /app3
</VirtualHost></tt></pre>
</div></div>
</td>
</tr></table>
</div>
<h3 id="_redeploying_restarting_the_ruby_on_rails_application">3.3. Redeploying (restarting the Ruby on Rails application)</h3><div style="clear:left"></div>
<div class="paragraph"><p>Deploying a new version of a Ruby on Rails application is as simple as
re-uploading the application files, and restarting the application.</p></div>
<div class="paragraph"><p>There are two ways to restart the application:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
By restarting Apache.
</p>
</li>
<li>
<p>
By creating or modifying the file <em>tmp/restart.txt</em> in the Rails
application’s <a href="#application_root">root folder</a>. Phusion Passenger will
automatically restart the application during the next request.
</p>
</li>
</ol></div>
<div class="paragraph"><p>For example, to restart our example MyCook application, we type this in the
command line:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>touch /webapps/mycook/tmp/restart.txt</tt></pre>
</div></div>
<div class="paragraph"><p>Please note that, unlike earlier versions of Phusion Passenger, <em>restart.txt</em>
is not automatically deleted. Phusion Passenger checks whether the timestamp
of this file has changed in order to determine whether the application should
be restarted.</p></div>
<h3 id="_migrations">3.4. Migrations</h3><div style="clear:left"></div>
<div class="paragraph"><p>Phusion 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 <em>ssh</em>) and type <tt>rake db:migrate RAILS_ENV=production</tt> in
a shell console, just like one would normally run migrations.</p></div>
<h3 id="_capistrano_integration">3.5. Capistrano integration</h3><div style="clear:left"></div>
<div class="paragraph"><p>See <a href="#capistrano">Capistrano recipe</a>.</p></div>
</div>
<h2 id="_deploying_a_rack_based_ruby_application">4. Deploying a Rack-based Ruby application</h2>
<div class="sectionbody">
<div class="paragraph"><p>Phusion Passenger supports arbitrary Ruby web applications that follow the
<a href="http://rack.rubyforge.org/">Rack</a> interface.</p></div>
<div class="paragraph"><p>Phusion Passenger assumes that Rack application directories have a certain layout.
Suppose that you have a Rack application in <em>/webapps/rackapp</em>. Then that
folder must contain at least three entries:</p></div>
<div class="ulist"><ul>
<li>
<p>
<em>config.ru</em>, a Rackup file for starting the Rack application. This file must contain
the complete logic for initializing the application.
</p>
</li>
<li>
<p>
<em>public/</em>, a folder containing public static web assets, like images and stylesheets.
</p>
</li>
<li>
<p>
<em>tmp/</em>, used for <em>restart.txt</em> (our application restart mechanism). This will
be explained in a following subsection.
</p>
</li>
</ul></div>
<div class="paragraph"><p>So <em>/webapps/rackapp</em> must, at minimum, look like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>/webapps/rackapp
|
+-- config.ru
|
+-- public/
|
+-- tmp/</tt></pre>
</div></div>
<div class="paragraph"><p>Suppose you own the domain <em>www.rackapp.com</em>. You can either deploy your application
to the virtual host’s root (i.e. the application will be accessible from the root URL,
<em>http://www.rackapp.com/</em>), or in a sub URI (i.e. the application will be
accessible from a sub URL, such as <em>http://www.rackapp.com/rackapp</em>).</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">The default <tt>RACK_ENV</tt> environment in which deployed Rack applications
are run, is “production”. You can change this by changing the
<a href="#rack_env"><em>RackEnv</em></a> configuration option.</td>
</tr></table>
</div>
<h3 id="_tutorial_example_writing_and_deploying_a_hello_world_rack_application">4.1. Tutorial/example: writing and deploying a Hello World Rack application</h3><div style="clear:left"></div>
<div class="paragraph"><p>First we create a Phusion Passenger-compliant Rack directory structure:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>$ mkdir /webapps/rack_example
$ mkdir /webapps/rack_example/public
$ mkdir /webapps/rack_example/tmp</tt></pre>
</div></div>
<div class="paragraph"><p>Next, we write a minimal "hello world" Rack application:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>$ cd /webapps/rack_example
$ some_awesome_editor config.ru
...type in some source code...
$ cat config.ru
app = proc do |env|
[200, { "Content-Type" => "text/html" }, ["hello <b>world</b>"]]
end
run app</tt></pre>
</div></div>
<div class="paragraph"><p>Finally, we deploy it by adding the following configuration options to
the Apache configuration file:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.rackexample.com
DocumentRoot /webapps/rack_example/public
<Directory /webapps/rack_example/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>And we’re done! After an Apache restart, the above Rack application will be available
under the URL <em>http://www.rackexample.com/</em>.</p></div>
<h3 id="_deploying_to_a_virtual_host_8217_s_root_2">4.2. Deploying to a virtual host’s root</h3><div style="clear:left"></div>
<div class="paragraph"><p>Add a virtual host entry to your Apache configuration file. Make sure that the
following conditions are met:</p></div>
<div class="ulist"><ul>
<li>
<p>
The virtual host’s document root must point to your Rack application’s
<em>public</em> folder.
</p>
</li>
<li>
<p>
The Apache per-directory permissions must allow access to this folder.
</p>
</li>
<li>
<p>
MultiViews must be disabled for this folder.
</p>
</li>
</ul></div>
<div class="paragraph"><p>For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.rackapp.com
DocumentRoot /webapps/rackapp/public
<Directory /webapps/rackapp/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>You may also need to tweak your file/folder permissions. Make sure that the
following folders are readable and executable by Apache:</p></div>
<div class="ulist"><ul>
<li>
<p>
this <em>public</em> folder.
</p>
</li>
<li>
<p>
the application’s <em>config</em> folder.
</p>
</li>
<li>
<p>
all parent folders. That is, /webapps/rackapp and /webapps must also be readable and executable by Apache.
</p>
</li>
</ul></div>
<div class="paragraph"><p>Then restart Apache. The application has now been deployed.</p></div>
<h3 id="deploying_rack_to_sub_uri">4.3. Deploying to a sub URI</h3><div style="clear:left"></div>
<div class="paragraph"><p>Suppose that you already have a virtual host:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>And you want your Rack application to be accessible from the URL
<em>http://www.phusion.nl/rack</em>.</p></div>
<div class="paragraph"><p>To do this, make a symlink from your Rack application’s <em>public</em>
folder to a directory in the document root. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>ln -s /webapps/rackapp/public /websites/phusion/rack</tt></pre>
</div></div>
<div class="paragraph"><p>Next, add a <a href="#RackBaseURI">RackBaseURI</a> option to the virtual host configuration,
and also make sure that:</p></div>
<div class="ulist"><ul>
<li>
<p>
The Apache per-directory permissions allow access to this folder.
</p>
</li>
<li>
<p>
MultiViews is disabled for this folder.
</p>
</li>
</ul></div>
<div class="paragraph"><p>For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
RackBaseURI /rails # <-- These lines have
<Directory /websites/phusion/rails> # <-- been added.
Options -MultiViews # <--
</Directory> # <--
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>Then restart Apache. The application has now been deployed.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">
<div class="paragraph"><p>You can deploy multiple Rack applications under a virtual host, by specifying
<a href="#RackBaseURI">RackBaseURI</a> multiple times. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
....
RackBaseURI /app1
RackBaseURI /app2
RackBaseURI /app3
</VirtualHost></tt></pre>
</div></div>
</td>
</tr></table>
</div>
<h3 id="_redeploying_restarting_the_rack_application">4.4. Redeploying (restarting the Rack application)</h3><div style="clear:left"></div>
<div class="paragraph"><p>Deploying a new version of a Rack application is as simple as
re-uploading the application files, and restarting the application.</p></div>
<div class="paragraph"><p>There are two ways to restart the application:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
By restarting Apache.
</p>
</li>
<li>
<p>
By creating or modifying the file <em>tmp/restart.txt</em> in the Rack
application’s <a href="#application_root">root folder</a>. Phusion Passenger will
automatically restart the application.
</p>
</li>
</ol></div>
<div class="paragraph"><p>For example, to restart our example application, we type this in the
command line:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>touch /webapps/rackapp/tmp/restart.txt</tt></pre>
</div></div>
<h3 id="_rackup_specifications_for_various_web_frameworks">4.5. Rackup specifications for various web frameworks</h3><div style="clear:left"></div>
<div class="paragraph"><p>This subsection shows example <em>config.ru</em> files for various web frameworks.</p></div>
<h4 id="_camping">4.5.1. Camping</h4>
<div class="listingblock">
<div class="content">
<pre><tt>require 'rubygems'
require 'rack'
require 'camping'
##### Begin Camping application
Camping.goes :Blog
...your application code here...
##### End Camping application
run Rack::Adapter::Camping.new(Blog)</tt></pre>
</div></div>
<div class="paragraph"><p>For Camping versions 2.0 and up, using <tt>run Blog</tt> as the final line will do.</p></div>
<h4 id="_halcyon">4.5.2. Halcyon</h4>
<div class="listingblock">
<div class="content">
<pre><tt>require 'rubygems'
require 'halcyon'
$LOAD_PATH.unshift(Halcyon.root / 'lib')
Halcyon::Runner.load_config Halcyon.root/'config'/'config.yml'
run Halcyon::Runner.new</tt></pre>
</div></div>
<h4 id="_mack">4.5.3. Mack</h4>
<div class="listingblock">
<div class="content">
<pre><tt>ENV["MACK_ENV"] = ENV["RACK_ENV"]
load("Rakefile")
require 'rubygems'
require 'mack'
run Mack::Utils::Server.build_app</tt></pre>
</div></div>
<h4 id="_merb">4.5.4. Merb</h4>
<div class="listingblock">
<div class="content">
<pre><tt>require 'rubygems'
require 'merb-core'
Merb::Config.setup(
:merb_root => ::File.expand_path(::File.dirname(__FILE__)),
:environment => ENV['RACK_ENV']
)
Merb.environment = Merb::Config[:environment]
Merb.root = Merb::Config[:merb_root]
Merb::BootLoader.run
run Merb::Rack::Application.new</tt></pre>
</div></div>
<h4 id="_ramaze">4.5.5. Ramaze</h4>
<div class="listingblock">
<div class="content">
<pre><tt>require "rubygems"
require "ramaze"
Ramaze.trait[:essentials].delete Ramaze::Adapter
require "start"
Ramaze.start!
run Ramaze::Adapter::Base</tt></pre>
</div></div>
<h4 id="_sinatra">4.5.6. Sinatra</h4>
<div class="listingblock">
<div class="content">
<pre><tt>require 'rubygems'
require 'sinatra'
require 'app.rb'
run Sinatra::Application</tt></pre>
</div></div>
</div>
<h2 id="_configuring_phusion_passenger">5. Configuring Phusion Passenger</h2>
<div class="sectionbody">
<div class="paragraph"><p>After installation, Phusion Passenger does not need any further configurations.
Nevertheless, the system administrator may be interested in changing
Phusion Passenger’s behavior. Phusion Passenger’s Apache module supports the
following configuration options:</p></div>
<h3 id="_passengerroot_lt_directory_gt">5.1. PassengerRoot <directory></h3><div style="clear:left"></div>
<div class="paragraph"><p>The location to the Phusion Passenger root directory. This configuration option
is essential to Phusion Passenger, and allows Phusion Passenger to locate its own
data files. The correct value is given by the installer.</p></div>
<div class="paragraph"><p>If you’ve moved Phusion Passenger to a different directory then you need to update
this option as well. Please read
<a href="#moving_phusion_passenger">Moving Phusion Passenger to a different directory</a> for more information.</p></div>
<div class="paragraph"><p>This required option may only occur once, in the global server configuration.</p></div>
<h3 id="_passengerloglevel_lt_integer_gt">5.2. PassengerLogLevel <integer></h3><div style="clear:left"></div>
<div class="paragraph"><p>This option allows one to specify how much information Phusion Passenger should
write to the Apache error log file. A higher log level value means that more
information will be logged.</p></div>
<div class="paragraph"><p>Possible values are:</p></div>
<div class="ulist"><ul>
<li>
<p>
<em>0</em>: Show only errors and warnings.
</p>
</li>
<li>
<p>
<em>1</em>: Show the most important debugging information. This might be useful for
system administrators who are trying to figure out the cause of a
problem.
</p>
</li>
<li>
<p>
<em>2</em>: Show more debugging information. This is typically only useful for developers.
</p>
</li>
<li>
<p>
<em>3</em>: Show even more debugging information.
</p>
</li>
</ul></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default is <em>0</em>.</p></div>
<h3 id="PassengerRuby">5.3. PassengerRuby <filename></h3><div style="clear:left"></div>
<div class="paragraph"><p>This option allows one to specify the Ruby interpreter to use.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default is <em>ruby</em>.</p></div>
<h3 id="PassengerAppRoot">5.4. PassengerAppRoot <path/to/root></h3><div style="clear:left"></div>
<div class="paragraph"><p>By default, Phusion Passenger assumes that the application’s root directory
is the parent directory of the <em>public</em> directory. This option allows one to
specify the application’s root independently from the DocumentRoot, which
is useful if the <em>public</em> directory lives in a non-standard place.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <tt>AllowOverride Options</tt> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once.</p></div>
<div class="paragraph"><p>Example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost test.host>
DocumentRoot /var/rails/zena/sites/example.com/public
PassengerAppRoot /var/rails/zena # <-- normally Phusion Passenger would
# have assumed that the application
# root is "/var/rails/zena/sites/example.com"
</VirtualHost></tt></pre>
</div></div>
<h3 id="PassengerUseGlobalQueue">5.5. PassengerUseGlobalQueue <on|off></h3><div style="clear:left"></div>
<div class="paragraph"><p>Turns the use of global queuing on or off.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>off</em>.</p></div>
<div class="paragraph"><p><em>This feature is sponsored by <a href="http://www.37signals.com/">37signals</a>.</em></p></div>
<div class="paragraph"><div class="title">What does this option do?</div><p>Recall that Phusion Passenger spawns multiple backend processes (e.g. multiple
Ruby on Rails processes), each which processes HTTP requests serially. One of
Phusion Passenger’s jobs is to forward HTTP requests to a suitable backend
process. A backend process may take an arbitrary amount of time to process a
specific HTTP request. If the websites are (temporarily) under high load, and
the backend processes cannot process the requests fast enough, then some
requests may have to be queued.</p></div>
<div class="paragraph"><p>If global queuing is turned off, then Phusion Passenger will use <em>fair load
balancing</em>. This means that each backend process will have its own private
queue. Phusion Passenger will forward an HTTP request to the backend process
that has the least amount of requests in its queue.</p></div>
<div class="paragraph"><p>If global queuing is turned on, then Phusion Passenger will use a global queue
that’s shared between all backend processes. If an HTTP request comes in, and
all the backend processes are still busy, then Phusion Passenger will wait until
at least one backend process is done, and will then forward the request to that
process.</p></div>
<div class="paragraph"><div class="title">When to turn on global queuing?</div><p>You should turn on global queuing if one of your web applications may have
long-running requests.</p></div>
<div class="paragraph"><p>For example suppose that:</p></div>
<div class="ulist"><ul>
<li>
<p>
global queuing is turned off.
</p>
</li>
<li>
<p>
we’re currently in a state where all backend processes have 3 requests in
their queue, except for a single backend process, which has 1 request in its
queue.
</p>
</li>
</ul></div>
<div class="paragraph"><p>The situation looks like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Backend process A: [* ] (1 request in queue)
Backend process B: [*** ] (3 requests in queue)
Backend process C: [*** ] (3 requests in queue)
Backend process D: [*** ] (3 requests in queue)</tt></pre>
</div></div>
<div class="paragraph"><p>Each process is currently serving short-running requests.</p></div>
<div class="paragraph"><p>Phusion Passenger will forward the next request to backend process A. A will
now have 2 items in its queue. We’ll mark this new request with an X:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Backend process A: [*X ] (2 request in queue)
Backend process B: [*** ] (3 requests in queue)
Backend process C: [*** ] (3 requests in queue)
Backend process D: [*** ] (3 requests in queue)</tt></pre>
</div></div>
<div class="paragraph"><p>Assuming that B, C and D still aren’t done with their current request, the next
HTTP request - let’s call this Y - will be forwarded to backend process A as
well, because it has the least number of items in its queue:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Backend process A: [*XY ] (3 requests in queue)
Backend process B: [*** ] (3 requests in queue)
Backend process C: [*** ] (3 requests in queue)
Backend process D: [*** ] (3 requests in queue)</tt></pre>
</div></div>
<div class="paragraph"><p>But if request X happens to be a long-running request that needs 60 seconds to
complete, then we’ll have a problem. Y won’t be processed for at least 60
seconds. It would have been a better idea if Y was forward to processes B, C or
D instead, because they only have short-living requests in their queues.</p></div>
<div class="paragraph"><p>This problem will be avoided entirely if you turn global queuing on. With global
queuing, all backend processes will share the same queue. The first backend
process that becomes available will take from the queue, and so this
“queuing-behind-long-running-request” problem will never occur.</p></div>
<div class="paragraph"><p>Turning global queuing off will yield a minor performance improvement (about 5%,
depending on how fast/slow your web application is), which is why it’s off by
default.</p></div>
<h3 id="PassengerUserSwitching">5.6. PassengerUserSwitching <on|off></h3><div style="clear:left"></div>
<div class="paragraph"><p>Whether to enable <a href="#user_switching">user switching support</a>.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default value is <em>on</em>.</p></div>
<h3 id="PassengerDefaultUser">5.7. PassengerDefaultUser <username></h3><div style="clear:left"></div>
<div class="paragraph"><p>Phusion Passenger enables <a href="#user_switching">user switching support</a> by default.
This configuration option allows one to specify which user Rails/Rack
applications must run as, if user switching fails or is disabled.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default value is <em>nobody</em>.</p></div>
<h3 id="_passengerenabled_lt_on_off_gt">5.8. PassengerEnabled <on|off></h3><div style="clear:left"></div>
<div class="paragraph"><p>You can set this option to <em>off</em> to completely disable Phusion Passenger for
a certain location. This is useful if, for example, you want to integrate a PHP
application into the same virtual host as a Rails application.</p></div>
<div class="paragraph"><p>Suppose that you have a Rails application in <em>/apps/foo</em>. Suppose that you’ve
dropped Wordpress — a blogging application written in PHP — in
<em>/apps/foo/public/wordpress</em>. You can then configure Phusion Passenger as
follows:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.foo.com
DocumentRoot /apps/foo/public
<Directory /apps/foo/public/wordpress>
PassengerEnabled off
AllowOverride all # <-- Makes Wordpress's .htaccess file work.
</Directory>
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>This way, Phusion Passenger will not interfere with Wordpress.</p></div>
<div class="paragraph"><p><em>PassengerEnabled</em> may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>on</em>.</p></div>
<h3 id="PassengerTempDir">5.9. PassengerTempDir <directory></h3><div style="clear:left"></div>
<div class="paragraph"><p>Specifies the directory that Phusion Passenger should use for storing temporary
files. This includes things such as Unix socket files, buffered file uploads
(see also <a href="#PassengerUploadBufferDir">PassengerUploadBufferDir</a>), etc.</p></div>
<div class="paragraph"><p>This option may be specified once, in the global server configuration. The
default temp directory that Phusion Passenger uses is <em>/tmp</em>.</p></div>
<div class="paragraph"><p>This option is especially useful if Apache is not allowed to write to /tmp
(which is the case on some systems with strict SELinux policies) or if the
partition that /tmp lives on doesn’t have enough disk space.</p></div>
<div class="paragraph"><div class="title">Command line tools</div><p>Some Phusion Passenger command line administration tools, such as
<tt>passenger-status</tt>, must know what Phusion Passenger’s temp directory is
in order to function properly. You can pass the directory through the
<tt>PASSENGER_TMPDIR</tt> environment variable, or the <tt>TMPDIR</tt> environment variable
(the former will be used if both are specified).</p></div>
<div class="paragraph"><p>For example, if you set <em>PassengerTempDir</em> to <em>/my_temp_dir</em>, then invoke
<tt>passenger-status</tt> after you’ve set the <tt>PASSENGER_TMPDIR</tt> or <tt>TMPDIR</tt>
environment variable, like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>export PASSENGER_TMPDIR=/my_temp-dir
sudo -E passenger-status
# The -E option tells 'sudo' to preserve environment variables.</tt></pre>
</div></div>
<h3 id="PassengerUploadBufferDir">5.10. PassengerUploadBufferDir <directory></h3><div style="clear:left"></div>
<div class="paragraph"><p>Phusion Passenger buffers large file uploads to disk in order prevent slow file
uploads from blocking web applications. By default, a subdirectory in the
system’s temporary files directory (or a subdirectory in the directory specified
in <a href="#PassengerTempDir">PassengerTempDir</a>, if set) is automatically created for
storing these buffered file uploads.</p></div>
<div class="paragraph"><p>This configuration directive allows you to specify a different directory for storing
buffered file uploads. If you’ve specified such a directory (as opposed to using
Phusion Passenger’s default) then you <strong>must</strong> ensure that this directory exists.</p></div>
<div class="paragraph"><p>This configuration directive is also useful if you’re using apache2-mpm-itk.
The buffered file upload directory that Phusion Passenger creates by default has
very strict permissions: it can only be accessed by the Apache worker processes.
However, Phusion Passenger assumes that all Apache worker processes are running
as the same user. apache2-mpm-itk breaks this assumption by running multiple
Apache worker processes as different users. So if you’re using apace2-mpm-itk,
you should set this option to a directory that is writable by all Apache worker
processes, such as <em>/tmp</em>.</p></div>
<div class="paragraph"><p>You may specify <em>PassengerUploadBufferDir</em> in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <tt>AllowOverrides Options</tt> is enabled.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once.</p></div>
<h3 id="_passengerrestartdir_lt_directory_gt">5.11. PassengerRestartDir <directory></h3><div style="clear:left"></div>
<div class="paragraph"><p>As described in the deployment chapters of this document, Phusion Passenger
checks the file <em>tmp/restart.txt</em> in the applications'
<a href="#application_root">root directory</a> for restarting applications. Sometimes it
may be desirable for Phusion Passenger to look in a different directory instead,
for example for security reasons (see below). This option allows you to
customize the directory in which <em>restart.txt</em> is searched for.</p></div>
<div class="paragraph"><p>You may specify <em>PassengerRestartDir</em> in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <tt>AllowOverrides Options</tt> is enabled.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once.</p></div>
<div class="paragraph"><p>You can either set it to an absolute directory, or to a directory relative to
the <a href="#application_root">application root</a>. Examples:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.foo.com
# Phusion Passenger will check for /apps/foo/public/tmp/restart.txt
DocumentRoot /apps/foo/public
</VirtualHost>
<VirtualHost *:80>
ServerName www.bar.com
DocumentRoot /apps/bar/public
# An absolute filename is given; Phusion Passenger will
# check for /restart_files/bar/restart.txt
PassengerRestartDir /restart_files/bar
</VirtualHost>
<VirtualHost *:80>
ServerName www.baz.com
DocumentRoot /apps/baz/public
# A relative filename is given; Phusion Passenger will
# check for /apps/baz/restart_files/restart.txt
#
# Note that this directory is relative to the APPLICATION ROOT, *not*
# the value of DocumentRoot!
PassengerRestartDir restart_files
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><div class="title">What are the security reasons for wanting to customize PassengerRestartDir?</div><p>Touching restart.txt will cause Phusion Passenger to restart the application.
So anybody who can touch restart.txt can effectively cause a Denial-of-Service
attack by touching restart.txt over and over. If your web server or one of your
web applications has the permission to touch restart.txt, and one of them has a
security flaw which allows an attacker to touch restart.txt, then that will
allow the attacker to cause a Denial-of-Service.</p></div>
<div class="paragraph"><p>You can prevent this from happening by pointing PassengerRestartDir to a
directory that’s readable by Apache, but only writable by administrators.</p></div>
<h3 id="_resource_control_and_optimization_options">5.12. Resource control and optimization options</h3><div style="clear:left"></div>
<h4 id="_passengermaxpoolsize_lt_integer_gt">5.12.1. PassengerMaxPoolSize <integer></h4>
<div class="paragraph"><p>The maximum number of Ruby on Rails or Rack application instances that may
be simultaneously active. A larger number results in higher memory usage,
but improved ability to handle concurrent HTTP clients.</p></div>
<div class="paragraph"><p>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 <em>30</em>.
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 <em>2</em>.</p></div>
<div class="paragraph"><p>If you find that your server is unable to handle the load on your Rails/Rack 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.)</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default value is <em>6</em>.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">We strongly recommend you to <a href="#reducing_memory_usage">use Ruby Enterprise Edition</a>. This allows you to reduce the memory usage of your Ruby on Rails applications
by about 33%. And it’s not hard to install.</td>
</tr></table>
</div>
<h4 id="_passengermaxinstancesperapp_lt_integer_gt">5.12.2. PassengerMaxInstancesPerApp <integer></h4>
<div class="paragraph"><p>The maximum number of application instances that may be simultaneously active
for a single application. This helps to make sure that a single application
will not occupy all available slots in the application pool.</p></div>
<div class="paragraph"><p>This value must be less than <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a>. A value of 0
means that there is no limit placed on the number of instances a single application
may use, i.e. only the global limit of <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a>
will be enforced.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default value is <em>0</em>.</p></div>
<h4 id="PassengerPoolIdleTime">5.12.3. PassengerPoolIdleTime <integer></h4>
<div class="paragraph"><p>The maximum number of seconds that an application instance may be idle. That is,
if an application instance hasn’t received any traffic after the given number of
seconds, then it will be shutdown in order to conserve memory.</p></div>
<div class="paragraph"><p>Decreasing this value means that 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/Rack website. However, it will also
free up resources used by applications more quickly.</p></div>
<div class="paragraph"><p>The optimal value depends on the average time that a visitor spends on a single
Rails/Rack web page. We recommend a value of <tt>2 * x</tt>, where <tt>x</tt> is the average
number of seconds that a visitor spends on a single Rails/Rack web page. But your
mileage may vary.</p></div>
<div class="paragraph"><p>When this value is set to <em>0</em>, application instances will not be shutdown unless
it’s really necessary, i.e. when Phusion Passenger is out of worker processes
for a given application and one of the inactive application instances needs to
make place for another application instance. Setting the value to 0 is
recommended if you’re on a non-shared host that’s only running a few
applications, each which must be available at all times.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default value is <em>300</em>.</p></div>
<h4 id="PassengerMaxRequests">5.12.4. PassengerMaxRequests <integer></h4>
<div class="paragraph"><p>The maximum number of requests an application instance will process. After
serving that many requests, the application instance will be shut down and
Phusion Passenger will restart it. A value of 0 means that there is no maximum:
an application instance will thus be shut down when its idle timeout has been
reached.</p></div>
<div class="paragraph"><p>This option is useful if your application is leaking memory. By shutting
it down after a certain number of requests, all of its memory is guaranteed
to be freed by the operating system.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <tt>AllowOverride Limits</tt> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>0</em>.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/caution.png" alt="Caution" />
</td>
<td class="content">
<div class="paragraph"><p>The <a href="#PassengerMaxRequests">PassengerMaxRequests</a> directive should be considered
as a workaround for misbehaving applications. It is advised that you fix the
problem in your application rather than relying on these directives as a
measure to avoid memory leaks.</p></div>
</td>
</tr></table>
</div>
<h4 id="_passengerstatthrottlerate_lt_integer_gt">5.12.5. PassengerStatThrottleRate <integer></h4>
<div class="paragraph"><p>By default, Phusion Passenger performs several filesystem checks (or, in
programmers jargon, <em>stat() calls</em>) each time a request is processed:</p></div>
<div class="ulist"><ul>
<li>
<p>
It checks whether <em>config/environment.rb</em>, <em>config.ru</em> or <em>passenger_wsgi.py</em>
is present, in order to autodetect Rails, Rack and WSGI applications.
</p>
</li>
<li>
<p>
It checks whether <em>restart.txt</em> has changed or whether <em>always_restart.txt</em>
exists, in order to determine whether the application should be restarted.
</p>
</li>
</ul></div>
<div class="paragraph"><p>On some systems where disk I/O is expensive, e.g. systems where the harddisk is
already being heavily loaded, or systems where applications are stored on NFS
shares, these filesystem checks can incur a lot of overhead.</p></div>
<div class="paragraph"><p>You can decrease or almost entirely eliminate this overhead by setting
<em>PassengerStatThrottleRate</em>. Setting this option to a value of <em>x</em> means that
the above list of filesystem checks will be performed at most once every <em>x</em>
seconds. Setting it to a value of <em>0</em> means that no throttling will take place,
or in other words, that the above list of filesystem checks will be performed on
every request.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <tt>AllowOverride Limits</tt> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>0</em>.</p></div>
<h4 id="PassengerHighPerformance">5.12.6. PassengerHighPerformance <on|off></h4>
<div class="paragraph"><p>By default, Phusion Passenger is compatible with mod_rewrite and most other
Apache modules. However, a lot of effort is required in order to be compatible.
If you turn <em>PassengerHighPerformance</em> to <em>on</em>, then Phusion Passenger will be
a little faster, in return for reduced compatibility with other Apache modules.</p></div>
<div class="paragraph"><p>In places where <em>PassengerHighPerformance</em> is turned on, mod_rewrite rules will
likely not work. mod_autoindex (the module which displays a directory index)
will also not work. Other Apache modules may or may not work, depending on what
they exactly do. We recommend you to find out how other modules behave in high
performance mode via testing.</p></div>
<div class="paragraph"><p>This option is <strong>not</strong> an all-or-nothing global option: you can enable high
performance mode for certain virtual hosts or certain URLs only.
The <em>PassengerHighPerformance</em> option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>off</em>,
so high performance mode is disabled by default, and you have to explicitly
enable it.</p></div>
<div class="paragraph"><div class="title">When to enable high performance mode?</div><p>If you do not use mod_rewrite or other Apache modules then it might make
sense to enable high performance mode.</p></div>
<div class="paragraph"><p>It’s likely that some of your applications depend on mod_rewrite or other
Apache modules, while some do not. In that case you can enable high performance
for only those applications that don’t use other Apache modules. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.foo.com
DocumentRoot /apps/foo/public
.... mod_rewrite rules or options for other Apache modules here ...
</VirtualHost>
<VirtualHost *:80>
ServerName www.bar.com
DocumentRoot /apps/bar/public
PassengerHighPerformance on
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>In the above example, high performance mode is only enabled for www.bar.com.
It is disabled for everything else.</p></div>
<div class="paragraph"><p>If your application generally depends on mod_rewrite or other Apache modules,
but a certain URL that’s accessed often doesn’t depend on those other modules,
then you can enable high performance mode for a certain URL only. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.foo.com
DocumentRoot /apps/foo/public
.... mod_rewrite rules or options for other Apache modules here ...
<Location /chatroom/ajax_update_poll>
PassengerHighPerformance on
</Location>
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>This enables high performance mode for
<a href="http://www.foo.com/chatroom/ajax_update_poll">http://www.foo.com/chatroom/ajax_update_poll</a> only.</p></div>
<h3 id="_compatibility_options">5.13. Compatibility options</h3><div style="clear:left"></div>
<h4 id="PassengerResolveSymlinksInDocumentRoot">5.13.1. PassengerResolveSymlinksInDocumentRoot <on|off></h4>
<div class="paragraph"><p>Configures whether Phusion Passenger should resolve symlinks in the document root.
Please refer to <a href="#application_detection">How Phusion Passenger detects whether a virtual host is a web application</a> for more information.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <tt>AllowOverride Options</tt> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. It is off by default.</p></div>
<h4 id="_passengerallowencodedslashes_lt_on_off_gt">5.13.2. PassengerAllowEncodedSlashes <on|off></h4>
<div class="paragraph"><p>By default, Apache doesn’t support URLs with encoded slashes (%2f), e.g. URLs like
this: <tt>/users/fujikura%2fyuu</tt>. If you access such an URL then Apache will return a
404 Not Found error. This can be solved by turning on PassengerAllowEncodedSlashes
as well as Apache’s
<a href="http://httpd.apache.org/docs/2.0/mod/core.html#allowencodedslashes">AllowEncodedSlashes</a>.</p></div>
<div class="paragraph"><p>Is it important that you turn on both AllowEncodedSlashes <strong>and</strong> PassengerAllowEncodedSlashes,
otherwise this feature will not work properly.</p></div>
<div class="paragraph"><p>PassengerAllowEncodedSlashes may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <tt>AllowOverride Options</tt> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. It is off by default.</p></div>
<div class="paragraph"><p>Please note however that turning on support for encoded slashes will break support for
mod_rewrite passthrough rules. Because of bugs/limitations in Apache, Phusion Passenger
can support either encoded slashes or mod_rewrite passthrough rules, but not both at the
same time. Luckily this option can be specified anywhere, so you can enable it only for
virtual hosts or URLs that need it:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><VirtualHost *:80>
ServerName www.example.com
DocumentRoot /webapps/example/public
AllowEncodedSlashes on
RewriteEngine on
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
# Make /about an alias for /info/about.
RewriteRule ^/about$ /info/about [PT,L]
<Location ~ "^/users/">
# In a location block so that it doesn't interfere with the
# above /about mod_rewrite rule.
PassengerAllowEncodedSlashes on
</Location>
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>With this, <a href="http://www.example.com/users/fujikura%2fyuu">http://www.example.com/users/fujikura%2fyuu</a> will work properly, and
accessing <a href="http://www.example.com/about">http://www.example.com/about</a> will properly display the result of
<a href="http://www.example.com/info/about">http://www.example.com/info/about</a>. Notice that PassengerAllowEncodedSlashes only
interferes with passthrough rules, not with any other mod_rewrite rules. The rules for
displaying maintenance.html will work fine even for URLs starting with "/users".</p></div>
<h3 id="_ruby_on_rails_specific_options">5.14. Ruby on Rails-specific options</h3><div style="clear:left"></div>
<h4 id="_railsautodetect_lt_on_off_gt">5.14.1. RailsAutoDetect <on|off></h4>
<div class="paragraph"><p>Whether Phusion Passenger should automatically detect whether a virtual host’s
document root is a Ruby on Rails application. The default is <em>on</em>.</p></div>
<div class="paragraph"><p>This option may occur in the global server configuration or in a virtual host
configuration block.</p></div>
<div class="paragraph"><p>For example, consider the following configuration:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>RailsAutoDetect off
<VirtualHost *:80>
ServerName www.mycook.com
DocumentRoot /webapps/mycook/public
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>If one goes to <em>http://www.mycook.com/</em>, the visitor will see the contents of
the <em>/webapps/mycook/public</em> folder, instead of the output of the Ruby on Rails
application.</p></div>
<div class="paragraph"><p>It is possible to explicitly specify that the host is a Ruby on Rails
application by using the <a href="#RailsBaseURI">RailsBaseURI</a> configuration option:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>RailsAutoDetect off
<VirtualHost *:80>
ServerName www.mycook.com
DocumentRoot /webapps/mycook/public
RailsBaseURI / # This line has been added.
</VirtualHost></tt></pre>
</div></div>
<h4 id="RailsBaseURI">5.14.2. RailsBaseURI <uri></h4>
<div class="paragraph"><p>Used to specify that the given URI is a Rails application. See
<a href="#deploying_rails_to_sub_uri">Deploying Rails to a sub URI</a> for an example.</p></div>
<div class="paragraph"><p>It is allowed to specify this option multiple times. Do this to deploy multiple
Rails applications in different sub-URIs under the same virtual host.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <tt>AllowOverride Options</tt> is on.
</p>
</li>
</ul></div>
<h4 id="rails_env">5.14.3. RailsEnv <string></h4>
<div class="paragraph"><p>This option allows one to specify the default <tt>RAILS_ENV</tt> value.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <tt>AllowOverride Options</tt> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>production</em>.</p></div>
<h4 id="RailsSpawnMethod">5.14.4. RailsSpawnMethod <string></h4>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">
<div class="title">"What spawn method should I use?"</div>
<div class="paragraph"><p>This subsection attempts to describe spawn methods, but it’s okay if you don’t (want to)
understand it, as it’s mostly a technical detail. You can basically follow this rule of thumb:</p></div>
<div class="sidebarblock">
<div class="sidebar-content">
<div class="paragraph"><p>If your application works on Mongrel, but not on Phusion Passenger, then set
<tt>RailsSpawnMethod</tt> to <em>conservative</em>. Otherwise, leave it at <em>smart-lv2</em> (the default).</p></div>
</div></div>
<div class="paragraph"><p>However, we do recommend you to try to understand it. The <em>smart</em> and <em>smart-lv2</em> spawn
methods bring many benefits.</p></div>
</td>
</tr></table>
</div>
<div class="paragraph"><p>Internally, Phusion Passenger spawns multiple Ruby on Rails processes in order to handle
requests. But there are multiple ways with which processes can be spawned, each having
its own set of pros and cons. Supported spawn methods are:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<em>smart</em>
</dt>
<dd>
<p>
When this spawn method is used, Phusion Passenger will attempt to cache Ruby on Rails
framework code and application code for a limited period of time. Please read
<a href="#spawning_methods_explained">Spawning methods explained</a> for a more detailed
explanation of what smart spawning exactly does.
</p>
<div class="paragraph"><p><strong>Pros:</strong>
This can significantly decrease spawn time (by as much as 90%). And, when Ruby Enterprise
Edition is used, <a href="#reducing_memory_usage">memory usage can be reduced by 33% on average</a>.</p></div>
<div class="paragraph"><p><strong>Cons:</strong>
Some Ruby on Rails applications and libraries are not compatible with smart spawning.
If that’s the case for your application, then you should use <em>conservative</em> as
spawning method.</p></div>
</dd>
<dt class="hdlist1">
<em>smart-lv2</em>
</dt>
<dd>
<p>
This spawning method is similar to <em>smart</em> but it skips the framework spawner
and uses the application spawner directly. This means the framework code is not
cached between multiple applications, although it is still cached within
instances of the same application. Please read
<a href="#spawning_methods_explained">Spawning methods explained</a> for a more detailed
explanation of what smart-lv2 spawning exactly does.
</p>
<div class="paragraph"><p><strong>Pros:</strong> It is compatible with a larger number of applications when compared to
the <em>smart</em> method, and still performs some caching.</p></div>
<div class="paragraph"><p><strong>Cons:</strong> It is slower than smart spawning if you have many applications which
use the same framework version. It is therefore advised that shared hosts use the
<em>smart</em> method instead.</p></div>
</dd>
<dt class="hdlist1">
<em>conservative</em>
</dt>
<dd>
<p>
This spawning method is similar to the one used in Mongrel Cluster. It does not
perform any code caching at all. Please read
<a href="#spawning_methods_explained">Spawning methods explained</a> for a more detailed
explanation of what conservative spawning exactly does.
</p>
<div class="paragraph"><p><strong>Pros:</strong>
Conservative spawning is guaranteed to be compatible with all Rails applications
and libraries.</p></div>
<div class="paragraph"><p><strong>Cons:</strong>
Much slower than smart spawning. Every spawn action will be equally slow, though no slower than
the startup time of a single server in Mongrel Cluster. Conservative spawning will also
render <a href="#reducing_memory_usage">Ruby Enterprise Edition’s memory reduction technology</a> useless.</p></div>
</dd>
</dl></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>smart-lv2</em>.</p></div>
<h4 id="_railsframeworkspawneridletime_lt_integer_gt">5.14.5. RailsFrameworkSpawnerIdleTime <integer></h4>
<div class="paragraph"><p>The FrameworkSpawner server (explained in <a href="#spawning_methods_explained">Spawning methods explained</a>) has an idle timeout, just like the backend processes spawned by
Phusion Passenger do. That is, it will automatically shutdown if it hasn’t done
anything for a given period.</p></div>
<div class="paragraph"><p>This option allows you to set the FrameworkSpawner server’s idle timeout, in
seconds. A value of <em>0</em> means that it should never idle timeout.</p></div>
<div class="paragraph"><p>Setting a higher value will mean that the FrameworkSpawner server is kept around
longer, which may slightly increase memory usage. But as long as the
FrameworkSpawner server is running, the time to spawn a Ruby on Rails backend
process only takes about 40% of the time that is normally needed, assuming that
you’re using the <em>smart</em> <a href="#RailsSpawnMethod">spawning method</a>. So if your
system has enough memory, is it recommended that you set this option to a high
value or to <em>0</em>.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>1800</em> (30 minutes).</p></div>
<h4 id="_railsappspawneridletime_lt_integer_gt">5.14.6. RailsAppSpawnerIdleTime <integer></h4>
<div class="paragraph"><p>The ApplicationSpawner server (explained in <a href="#spawning_methods_explained">Spawning methods explained</a>) has an idle timeout, just like the backend processes spawned by
Phusion Passenger do. That is, it will automatically shutdown if it hasn’t done
anything for a given period.</p></div>
<div class="paragraph"><p>This option allows you to set the ApplicationSpawner server’s idle timeout, in
seconds. A value of <em>0</em> means that it should never idle timeout.</p></div>
<div class="paragraph"><p>Setting a higher value will mean that the ApplicationSpawner server is kept around
longer, which may slightly increase memory usage. But as long as the
ApplicationSpawner server is running, the time to spawn a Ruby on Rails backend
process only takes about 10% of the time that is normally needed, assuming that
you’re using the <em>smart</em> or <em>smart-lv2</em> <a href="#RailsSpawnMethod">spawning method</a>. So if your
system has enough memory, is it recommended that you set this option to a high
value or to <em>0</em>.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>600</em> (10 minutes).</p></div>
<h3 id="_rack_specific_options">5.15. Rack-specific options</h3><div style="clear:left"></div>
<h4 id="_rackautodetect_lt_on_off_gt">5.15.1. RackAutoDetect <on|off></h4>
<div class="paragraph"><p>Whether Phusion Passenger should automatically detect whether a virtual host’s
document root is a Rack application. The default is <em>on</em>.</p></div>
<div class="paragraph"><p>This option may occur in the global server configuration or in a virtual host
configuration block.</p></div>
<div class="paragraph"><p>For example, consider the following configuration:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>RackAutoDetect off
<VirtualHost *:80>
ServerName www.rackapp.com
DocumentRoot /webapps/my_rack_app/public
</VirtualHost></tt></pre>
</div></div>
<div class="paragraph"><p>If one goes to <em>http://www.rackapp.com/</em>, the visitor will see the contents of
the <em>/webapps/my_rack_app/public</em> folder, instead of the output of the Rack
application.</p></div>
<div class="paragraph"><p>It is possible to explicitly specify that the host is a Rack
application by using the <a href="#RackBaseURI">RackBaseURI</a> configuration option:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>RackAutoDetect off
<VirtualHost *:80>
ServerName www.rackapp.com
DocumentRoot /webapps/my_rack_app/public
RackBaseURI / # This line was added
</VirtualHost></tt></pre>
</div></div>
<h4 id="RackBaseURI">5.15.2. RackBaseURI <uri></h4>
<div class="paragraph"><p>Used to specify that the given URI is a Rack application. See
<a href="#deploying_rack_to_sub_uri">Deploying Rack to a sub URI</a> for an example.</p></div>
<div class="paragraph"><p>It is allowed to specify this option multiple times. Do this to deploy multiple
Rack applications in different sub-URIs under the same virtual host.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <tt>AllowOverride Options</tt> is on.
</p>
</li>
</ul></div>
<h4 id="rack_env">5.15.3. RackEnv <string></h4>
<div class="paragraph"><p>The given value will be accessible in Rack applications in the <tt>RACK_ENV</tt>
environment variable. This allows one to define the environment in which
Rack applications are run, very similar to <tt>RAILS_ENV</tt>.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <tt><Directory></tt> or <tt><Location></tt> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <tt>AllowOverride Options</tt> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>production</em>.</p></div>
<h3 id="_deprecated_options">5.16. Deprecated options</h3><div style="clear:left"></div>
<div class="paragraph"><p>The following options have been deprecated, but are still supported for backwards
compatibility reasons.</p></div>
<h4 id="_railsruby">5.16.1. RailsRuby</h4>
<div class="paragraph"><p>Deprecated in favor of <a href="#PassengerRuby">PassengerRuby</a>.</p></div>
<h4 id="_railsuserswitching">5.16.2. RailsUserSwitching</h4>
<div class="paragraph"><p>Deprecated in favor of <a href="#PassengerUserSwitching">PassengerUserSwitching</a>.</p></div>
<h4 id="_railsdefaultuser">5.16.3. RailsDefaultUser</h4>
<div class="paragraph"><p>Deprecated in favor of <a href="#PassengerDefaultUser">PassengerDefaultUser</a>.</p></div>
<h4 id="_railsallowmodrewrite">5.16.4. RailsAllowModRewrite</h4>
<div class="paragraph"><p>This option doesn’t do anything anymore in recent versions of Phusion Passenger.</p></div>
</div>
<h2 id="_troubleshooting">6. Troubleshooting</h2>
<div class="sectionbody">
<h3 id="_operating_system_specific_problems">6.1. Operating system-specific problems</h3><div style="clear:left"></div>
<h4 id="_macos_x_the_installer_cannot_locate_mamp_8217_s_apache">6.1.1. MacOS X: The installer cannot locate MAMP’s Apache</h4>
<div class="sidebarblock">
<div class="sidebar-content">
<div class="sidebar-title">Symptoms</div>
<div class="paragraph"><p>The installer finds Apache 2 development headers at <tt>/Applications/MAMP/Library/bin/apxs</tt>.
However, Apache cannot be found. The installer also outputs the following error:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>cannot open /Applications/MAMP/Library/build/config_vars.mk:
No such file or directory at /Applications/MAMP/Library/bin/apxs line 218.</tt></pre>
</div></div>
</div></div>
<div class="paragraph"><p>Your MAMP installation seems to be broken. In particular, <em>config_vars.mk</em> is missing.
Please read <a href="http://forum.mamp.info/viewtopic.php?t=1866">this forum topic</a> to learn how
to fix this problem.</p></div>
<div class="paragraph"><p>See also <a href="http://code.google.com/p/phusion-passenger/issues/detail?id=12">this bug report</a>.</p></div>
<h3 id="_problems_during_installation">6.2. Problems during installation</h3><div style="clear:left"></div>
<h4 id="installing_ruby_dev">6.2.1. Ruby development headers aren’t installed</h4>
<div class="sidebarblock">
<div class="sidebar-content">
<div class="sidebar-title">Symptoms</div>
<div class="paragraph"><p>Installing Phusion Passenger fails because of one of the following errors:</p></div>
<div class="ulist"><ul>
<li>
<p>
The Phusion Passenger installer tells you that the Ruby development headers
aren’t installed.
</p>
</li>
<li>
<p>
The error message “'no such file to load — mkmf”' occurs.
</p>
</li>
<li>
<p>
The error message “'ruby.h: No such file or directory”' occurs.
</p>
</li>
</ul></div>
</div></div>
<div class="paragraph"><p>Phusion 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.</p></div>
<div class="paragraph"><p>Here’s how you can install the development headers:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
Ubuntu/Debian
</dt>
<dd>
<p>
Please type:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>sudo apt-get install ruby1.8-dev</tt></pre>
</div></div>
</dd>
<dt class="hdlist1">
Fedora/CentOS/RHEL
</dt>
<dd>
<p>
Please type:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>su -c 'yum install ruby-devel'</tt></pre>
</div></div>
</dd>
<dt class="hdlist1">
FreeBSD
</dt>
<dd>
<p>
Please install Ruby from <em>ports</em> or with <tt>pkg_add</tt>. If that fails,
please install Ruby from source.
</p>
</dd>
<dt class="hdlist1">
MacOS X
</dt>
<dd>
<p>
Please install Ruby from source.
</p>
</dd>
<dt class="hdlist1">
Other operating systems
</dt>
<dd>
<p>
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.
</p>
</dd>
</dl></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">If you’ve installed a new Ruby version (i.e. your system now contains
multiple Ruby installations), then you will need to tell Phusion Passenger
which Ruby installation you want to use. Please read
<a href="#specifying_ruby_installation">Specifying the correct Ruby installation</a>.</td>
</tr></table>
</div>
<h4 id="_apache_development_headers_aren_8217_t_installed">6.2.2. Apache development headers aren’t installed</h4>
<div class="sidebarblock">
<div class="sidebar-content">
<div class="sidebar-title">Symptoms</div>
<div class="paragraph"><p>Installing Phusion Passenger fails because of one of the following errors:</p></div>
<div class="ulist"><ul>
<li>
<p>
The installer says that the Apache development headers aren’t installed.
</p>
</li>
<li>
<p>
The error message “'httpd.h: No such file or directory”' occurs.
</p>
<div class="paragraph"><p>(Instead of <em>httpd.h</em>, the message might also be <em>http_config.h</em> or something
else similar to <em>http_*.h</em>.)</p></div>
</li>
</ul></div>
</div></div>
<div class="dlist"><dl>
<dt class="hdlist1">
Ubuntu
</dt>
<dd>
<p>
Please type:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>sudo apt-get install apache2-prefork-dev</tt></pre>
</div></div>
</dd>
<dt class="hdlist1">
Debian
</dt>
<dd>
<p>
Please type:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>sudo apt-get install apache2-dev</tt></pre>
</div></div>
</dd>
<dt class="hdlist1">
Fedora/CentOS/RHEL
</dt>
<dd>
<p>
Please type:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>su -c 'yum install httpd-devel'</tt></pre>
</div></div>
</dd>
<dt class="hdlist1">
FreeBSD
</dt>
<dd>
<p>
Please install Apache from <em>ports</em> or with <tt>pkg_add</tt>. If that fails,
please install Apache from source.
</p>
</dd>
<dt class="hdlist1">
MacOS X
</dt>
<dd>
<p>
Please install Apache from source.
</p>
</dd>
<dt class="hdlist1">
Other operating systems
</dt>
<dd>
<p>
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.
</p>
</dd>
</dl></div>
<h4 id="_apr_development_headers_aren_8217_t_installed">6.2.3. APR development headers aren’t installed</h4>
<div class="sidebarblock">
<div class="sidebar-content">
<div class="sidebar-title">Symptoms</div>
<div class="paragraph"><p>Installing Phusion Passenger fails because one of the following errors:</p></div>
<div class="ulist"><ul>
<li>
<p>
The installer tells you that APR development headers aren’t installed.
</p>
</li>
<li>
<p>
The error message “'apr_pools.h: No such file or directory”' occurs.
</p>
</li>
<li>
<p>
The error message “'apr_strings.h: No such file or directory”' occurs.
</p>
</li>
</ul></div>
</div></div>
<div class="dlist"><dl>
<dt class="hdlist1">
Ubuntu
</dt>
<dd>
<p>
Please type:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>sudo apt-get install libapr1-dev</tt></pre>
</div></div>
</dd>
<dt class="hdlist1">
Debian
</dt>
<dd>
<p>
Please type:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>sudo apt-get install libapr1-dev</tt></pre>
</div></div>
</dd>
<dt class="hdlist1">
Fedora/CentOS/RHEL
</dt>
<dd>
<p>
Please type:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>su -c 'yum install apr-devel'</tt></pre>
</div></div>
</dd>
<dt class="hdlist1">
Other Linux distributions
</dt>
<dd>
<p>
Please consult your distribution’s package database. There should be a
package which provides APR development headers.
</p>
</dd>
<dt class="hdlist1">
Other operating systems
</dt>
<dd>
<p>
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.
</p>
</dd>
</dl></div>
<h4 id="_phusion_passenger_is_using_the_wrong_apache_during_installation">6.2.4. Phusion Passenger is using the wrong Apache during installation</h4>
<div class="paragraph"><p>Please <a href="#specifying_correct_apache_install">Specifying the correct Apache installation</a>, and re-run the Phusion Passenger installer.</p></div>
<h4 id="_phusion_passenger_is_using_the_wrong_ruby_during_installation">6.2.5. Phusion Passenger is using the wrong Ruby during installation</h4>
<div class="paragraph"><p>Please <a href="#specifying_ruby_installation">Specifying the correct Ruby installation</a>, and re-run the Phusion Passenger installer.</p></div>
<h3 id="_problems_after_installation">6.3. Problems after installation</h3><div style="clear:left"></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">
<div class="title">The golden tip: read your Apache error logs!</div>
<div class="paragraph"><p><em>mod_passenger</em> 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.</p></div>
</td>
</tr></table>
</div>
<h4 id="_my_rails_application_works_on_mongrel_but_not_on_phusion_passenger">6.3.1. My Rails application works on Mongrel, but not on Phusion Passenger</h4>
<div class="paragraph"><p>Please try setting <a href="#RailsSpawnMethod">RailsSpawnMethod</a> to <em>conservative</em>.</p></div>
<h4 id="_phusion_passenger_has_been_compiled_against_the_wrong_apache_installation">6.3.2. Phusion Passenger has been compiled against the wrong Apache installation</h4>
<div class="sidebarblock">
<div class="sidebar-content">
<div class="sidebar-title">Symptoms</div>
<div class="paragraph"><p>Apache crashes during startup (after being daemonized). The Apache error log
says “'seg fault or similar nasty error detected in the parent process”'.</p></div>
</div></div>
<div class="paragraph"><p>This problem is most likely to occur on MacOS X. Most OS X users have multiple
Apache installations on their system.</p></div>
<div class="paragraph"><p>To solve this problem, please <a href="#specifying_correct_apache_install">specify the correct Apache installation</a>, and <a href="#install_passenger">reinstall Phusion Passenger</a>.</p></div>
<h4 id="_i_get_a_304_forbidden_error">6.3.3. I get a "304 Forbidden" error</h4>
<div class="paragraph"><p>See next subsection.</p></div>
<h4 id="_static_assets_such_as_images_and_stylesheets_aren_8217_t_being_displayed">6.3.4. Static assets such as images and stylesheets aren’t being displayed</h4>
<div class="paragraph"><p>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:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Your Apache configuration is too strict, and does not allow HTTP clients to
access static assets. This can be achieved with an <tt>Allow from all</tt> directive
in the correct place. For example:
</p>
<div class="listingblock">
<div class="content">
<pre><tt><Directory "/webapps/mycook/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory></tt></pre>
</div></div>
<div class="paragraph"><p>See also <a href="http://groups.google.com/group/phusion-passenger/browse_thread/thread/9699a639a87f85f4/b9d71a03bf2670a5">this discussion</a>.</p></div>
</li>
<li>
<p>
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.
</p>
</li>
</ol></div>
<h4 id="_the_apache_error_log_says_that_the_spawn_manager_script_does_not_exist_or_that_it_does_not_have_permission_to_execute_it">6.3.5. The Apache error log says that the spawn manager script does not exist, or that it does not have permission to execute it</h4>
<div class="paragraph"><p>If you are sure that the <em>PassengerRoot</em> 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.</p></div>
<div class="paragraph"><p>To solve this problem, you must set some permissions on the Phusion Passenger files
and folders, so that Apache can access them.</p></div>
<div class="ulist"><ul>
<li>
<p>
If you’ve installed Phusion Passenger via a gem, then run this command to determine
Phusion Passenger’s root folder:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>passenger-config --root</tt></pre>
</div></div>
<div class="paragraph"><p>Next, run the following command:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>chcon -R -h -t httpd_sys_content_t /path-to-passenger-root</tt></pre>
</div></div>
<div class="paragraph"><p>where <em>/path-to-passenger-root</em> should be replaced with whatever
<tt>passenger-config --root</tt> printed.</p></div>
</li>
<li>
<p>
If you’ve installed Phusion Passenger via the source tarball, then run the following
command:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>chcon -R -h -t httpd_sys_content_t /path/to/passenger/folder</tt></pre>
</div></div>
</li>
</ul></div>
<div class="paragraph"><p>Once the permissions are fixed, restart Apache.</p></div>
<h4 id="_the_rails_application_reports_that_it_8217_s_unable_to_start_because_of_a_permission_error">6.3.6. The Rails application reports that it’s unable to start because of a permission error</h4>
<div class="paragraph"><p>Please check whether your Rails application’s folder has the correct
permissions. By default, Rails applications are started as the owner of the
file <em>config/environment.rb</em>, except if the file is owned by root. If the
file is owned by root, then the Rails application will be started as <em>nobody</em>
(or as the user specify by <a href="#RailsDefaultUser">RailsDefaultUser</a>, if that’s
specified).</p></div>
<div class="paragraph"><p>Please read <a href="#user_switching">User switching (security)</a> for details.</p></div>
<h4 id="_my_rails_application_8217_s_log_file_is_not_being_written_to">6.3.7. My Rails application’s log file is not being written to</h4>
<div class="paragraph"><p>There are a couple things that you should be aware of:</p></div>
<div class="ulist"><ul>
<li>
<p>
By default, Phusion Passenger runs Rails applications in <em>production</em> mode,
so please be sure to check <em>production.log</em> instead of <em>development.log</em>. See
<a href="#RailsEnv">RailsEnv</a> for configuration.
</p>
</li>
<li>
<p>
By default, Phusion Passenger runs Rails applications as the owner of <em>environment.rb</em>.
So the log file can only be written to if that user has write permission to the
log file. Please <em>chmod</em> or <em>chown</em> your log file accordingly.
</p>
<div class="paragraph"><p>See <a href="#User_switching">User switching (security)</a> for details.</p></div>
</li>
</ul></div>
<div class="paragraph"><p>If you’re using a RedHat-derived Linux distribution (such as Fedora or CentOS)
then it is <a href="http://code.google.com/p/phusion-passenger/issues/detail?id=4">possible
that SELinux is interfering</a>. RedHat’s SELinux policy only allows Apache to read/write
directories that have the <em>httpd_sys_content_t</em> security context. Please run the
following command to give your Rails application folder that context:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>chcon -R -h -t httpd_sys_content_t /path/to/your/rails/app</tt></pre>
</div></div>
<h3 id="conflicting_apache_modules">6.4. Conflicting Apache modules</h3><div style="clear:left"></div>
<h4 id="_mod_userdir">6.4.1. mod_userdir</h4>
<div class="paragraph"><p><em>mod_userdir</em> is not compatible with Phusion Passenger at the moment.</p></div>
<h4 id="_multiviews_mod_negotiation">6.4.2. MultiViews (mod_negotiation)</h4>
<div class="paragraph"><p>MultiViews is not compatible with Phusion Passenger. You should disable MultiViews
for all Phusion Passenger hosts.</p></div>
<h4 id="_virtualdocumentroot">6.4.3. VirtualDocumentRoot</h4>
<div class="paragraph"><p>VirtualDocumentRoot is not compatible with Phusion Passenger at the moment.</p></div>
</div>
<h2 id="_analysis_and_system_maintenance_tools">7. Analysis and system maintenance tools</h2>
<div class="sectionbody">
<div class="paragraph"><p>Phusion Passenger provides a set of tools, which are useful for system analysis,
maintenance and troubleshooting.</p></div>
<h3 id="_inspecting_memory_usage">7.1. Inspecting memory usage</h3><div style="clear:left"></div>
<div class="paragraph"><p>Process inspection tools such as <tt>ps</tt> and <tt>top</tt> are useful, but they
<a href="http://groups.google.com/group/phusion-passenger/msg/1fd1c233456d3180">rarely show the correct memory usage</a>.
The real memory usage is usually lower than what <tt>ps</tt> and <tt>top</tt> report.</p></div>
<div class="paragraph"><p>There are many technical reasons why this is so, but an explanation is beyond
the scope of this Users Guide. We kindly refer the interested reader to
operating systems literature about <em>virtual memory</em> and <em>copy-on-write</em>.</p></div>
<div class="paragraph"><p>The tool <tt>passenger-memory-stats</tt> allows one to easily analyze Phusion Passenger’s
and Apache’s real memory usage. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>[bash@localhost root]# passenger-memory-stats
------------- Apache processes --------------.
PID PPID Threads VMSize Private Name
---------------------------------------------.
5947 1 9 90.6 MB 0.5 MB /usr/sbin/apache2 -k start
5948 5947 1 18.9 MB 0.7 MB /usr/sbin/fcgi-pm -k start
6029 5947 1 42.7 MB 0.5 MB /usr/sbin/apache2 -k start
6030 5947 1 42.7 MB 0.5 MB /usr/sbin/apache2 -k start
6031 5947 1 42.5 MB 0.3 MB /usr/sbin/apache2 -k start
6033 5947 1 42.5 MB 0.4 MB /usr/sbin/apache2 -k start
6034 5947 1 50.5 MB 0.4 MB /usr/sbin/apache2 -k start
23482 5947 1 82.6 MB 0.4 MB /usr/sbin/apache2 -k start
### Processes: 8
### Total private dirty RSS: 3.50 MB
--------- Passenger processes ---------.
PID Threads VMSize Private Name
---------------------------------------.
6026 1 10.9 MB 4.7 MB Passenger spawn server
23481 1 26.7 MB 3.0 MB Passenger FrameworkSpawner: 2.0.2
23791 1 26.8 MB 2.9 MB Passenger ApplicationSpawner: /var/www/projects/app1-foobar
23793 1 26.9 MB 17.1 MB Rails: /var/www/projects/app1-foobar
### Processes: 4
### Total private dirty RSS: 27.76 M</tt></pre>
</div></div>
<div class="paragraph"><p>The <em>Private</em> or <em>private dirty RSS</em> field shows the <strong>real</strong> memory usage of processes. Here,
we see that all the Apache worker processes only take less than 1 MB memory each.
This is a lot less than the 50 MB-ish memory usage as shown in the <em>VMSize</em> column
(which is what a lot of people think is the real memory usage, but is actually not).</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">Private dirty RSS reporting only works on Linux. Unfortunately other operating systems
don’t provide facilities for determining processes' private dirty RSS. On non-Linux systems,
the Resident Set Size is reported instead.</td>
</tr></table>
</div>
<h3 id="_inspecting_phusion_passenger_8217_s_internal_status">7.2. Inspecting Phusion Passenger’s internal status</h3><div style="clear:left"></div>
<div class="paragraph"><p>One can inspect Phusion Passenger’s internal status with the tool <tt>passenger-status</tt>.
This tool must typically be run as root. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>[bash@localhost root]# passenger-status
----------- General information -----------
max = 6
count = 1
active = 0
inactive = 1
----------- Domains -----------
/var/www/projects/app1-foobar:
PID: 9617 Sessions: 0 Processed: 7 Uptime: 2m 23s</tt></pre>
</div></div>
<div class="paragraph"><p>The <em>general information</em> section shows the following information:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
max
</dt>
<dd>
<p>
The maximum number of application instances that Phusion Passenger will
spawn. This equals the value given for <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a> (Apache)
or <a href="#PassengerMaxPoolSize">passenger_max_pool_size</a> (Nginx).
</p>
</dd>
<dt class="hdlist1">
count
</dt>
<dd>
<p>
The number of application instances that are currently alive. This value
is always less than or equal to <em>max</em>.
</p>
</dd>
<dt class="hdlist1">
active
</dt>
<dd>
<p>
The number of application instances that are currently processing
requests. This value is always less than or equal to <em>count</em>.
</p>
</dd>
<dt class="hdlist1">
inactive
</dt>
<dd>
<p>
The number of application instances that are currently <strong>not</strong> processing
requests, i.e. are idle. Idle application instances will be shutdown after a while,
as can be specified with <a href="#PassengerPoolIdleTime">PassengerPoolIdleTime (Apache)</a>/<a href="#PassengerPoolIdleTime">passenger_pool_idle_time (Nginx)</a> (unless this
value is set to 0, in which case application instances are never shut down via idle
time). The value of <em>inactive</em> equals <tt>count - active</tt>.
</p>
</dd>
</dl></div>
<div class="paragraph"><p>The <em>domains</em> section shows, for each application directory, information about running
application instances:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
Sessions
</dt>
<dd>
<p>
Shows how many HTTP client are currently in the queue of that application
Instance, waiting to be processed.
</p>
</dd>
<dt class="hdlist1">
Processed
</dt>
<dd>
<p>
Indicates how many requests the instance has served until now. <strong>Tip:</strong> it’s
possible to limit this number with the <a href="#PassengerMaxRequests">PassengerMaxRequests</a>
configuration directive.
</p>
</dd>
<dt class="hdlist1">
Uptime
</dt>
<dd>
<p>
Shows for how long the application instance has been running.
</p>
</dd>
</dl></div>
<div class="paragraph"><p>Since Phusion Passenger uses fair load balancing by default, the number of sessions for the
application instances should be fairly close to each other. For example, this is fairly
normal:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt> PID: 4281 Sessions: 2 Processed: 7 Uptime: 5m 11s
PID: 4268 Sessions: 0 Processed: 5 Uptime: 4m 52s
PID: 4265 Sessions: 1 Processed: 6 Uptime: 5m 38s
PID: 4275 Sessions: 1 Processed: 7 Uptime: 3m 14s</tt></pre>
</div></div>
<div class="paragraph"><p>But if you see a "spike", i.e. an application instance has an unusually high number of
sessions compared to the others, then there might be a problem:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt> PID: 4281 Sessions: 2 Processed: 7 Uptime: 5m 11s
PID: 17468 Sessions: 8 <-+ Processed: 2 Uptime: 4m 47s
PID: 4265 Sessions: 1 | Processed: 6 Uptime: 5m 38s
PID: 4275 Sessions: 1 | Processed: 7 Uptime: 3m 14s
|
+---- "spike"</tt></pre>
</div></div>
<div class="paragraph"><p>Possible reasons why spikes can occur:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Your application is busy processing a request that takes a very long time.
If this is the case, then you might want to turn
<a href="#PassengerUseGlobalQueue">global queuing</a> on.
</p>
</li>
<li>
<p>
Your application is frozen, i.e. has stopped responding. See
<a href="#debugging_frozen">Debugging frozen applications</a> for tips.
</p>
</li>
</ol></div>
<h3 id="debugging_frozen">7.3. Debugging frozen applications</h3><div style="clear:left"></div>
<div class="paragraph"><p>If one of your application instances is frozen (stopped responding), then you
can figure out where it is frozen by killing it with <em>SIGABRT</em>. This will cause the
application to raise an exception, with a backtrace.</p></div>
<div class="paragraph"><p>The exception (with full backtrace information) is normally logged into the Apache
error log. But if your application or if its web framework has its own exception logging
routines, then exceptions might be logged into the application’s log files instead.
This is the case with Ruby on Rails. So if you kill a Ruby on Rails application with
<em>SIGABRT</em>, please check the application’s <em>production.log</em> first (assuming that you’re
running it in a <em>production</em> environment). If you don’t see a backtrace there, check
the Apache error log.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">It is safe to kill application instances, even in live environments. Phusion Passenger
will restart killed application instances, as if nothing bad happened.</td>
</tr></table>
</div>
</div>
<h2 id="_tips">8. Tips</h2>
<div class="sectionbody">
<h3 id="user_switching">8.1. User switching (security)</h3><div style="clear:left"></div>
<div class="paragraph"><p>There is a problem that plagues most PHP web hosts, 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.</p></div>
<div class="paragraph"><p>Phusion Passenger solves this problem by implementing <em>user switching</em>. A Rails
application is started as the owner of the file <em>config/environment.rb</em>,
and a Rack application is started as the owner of the file <em>config.ru</em>.
So if <em>/home/webapps/foo/config/environment.rb</em> is owned by <em>joe</em>, then Phusion
Passenger will launch the corresponding Rails application as <em>joe</em> as well.</p></div>
<div class="paragraph"><p>This behavior is the default, and you don’t need to configure anything. But
there are things that you should keep in mind:</p></div>
<div class="ulist"><ul>
<li>
<p>
The owner of <em>environment.rb</em> must have read access to the Rails application’s
folder, and read/write access to the Rails application’s <em>logs</em> folder.
Likewise, the owner of <em>config.ru</em> must have read access to the Rack application’s
folder.
</p>
</li>
<li>
<p>
This feature is only available if Apache is started by <em>root</em>. This is the
case on most Apache installations.
</p>
</li>
<li>
<p>
Under no circumstances will applications be run as <em>root</em>. If
<em>environment.rb</em>/<em>config.ru</em> is owned as root or by an unknown user, then the
Rails/Rack application will run as the user specified by
<a href="#PassengerDefaultUser">PassengerDefaultUser (Apache)</a>/<a href="#PassengerDefaultUser">passenger_default_user (Nginx)</a>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>User switching can be disabled with the
<a href="#PassengerUserSwitching">PassengerUserSwitching (Apache)</a>/<a href="#PassengerUserSwitching">passenger_user_switching (Nginx)</a>
option.</p></div>
<h3 id="reducing_memory_usage">8.2. Reducing memory consumption of Ruby on Rails applications by 33%</h3><div style="clear:left"></div>
<div class="paragraph"><p>Is it possible to reduce memory consumption of your Rails applications by 33% on average,
by using <a href="http://www.rubyenterpriseedition.com/">Ruby Enterprise Edition</a>.
Please visit the website for details.</p></div>
<div class="paragraph"><p>Note that this feature does not apply to Rack applications.</p></div>
<h3 id="capistrano">8.3. Capistrano recipe</h3><div style="clear:left"></div>
<div class="paragraph"><p>Phusion Passenger can be combined with <a href="http://capify.org/">Capistrano</a>.
The following Capistrano recipe demonstrates Phusion Passenger support.
It assumes that you’re using Git as version control system.</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>set :application, "myapp"
set :domain, "example.com"
set :repository, "ssh://#{domain}/path-to-your-git-repo/#{application}.git"
set :use_sudo, false
set :deploy_to, "/path-to-your-web-app-directory/#{application}"
set :scm, "git"
role :app, domain
role :web, domain
role :db, domain, :primary => true
namespace :deploy do
task :start, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
end</tt></pre>
</div></div>
<h3 id="moving_phusion_passenger">8.4. Moving Phusion Passenger to a different directory</h3><div style="clear:left"></div>
<div class="paragraph"><p>It is possible to relocate the Phusion Passenger files to a different directory. It
involves two steps:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Moving the directory.
</p>
</li>
<li>
<p>
Updating the “PassengerRoot” configuration option in Apache.
</p>
</li>
</ol></div>
<div class="paragraph"><p>For example, if Phusion Passenger is located in <em>/opt/passenger/</em>, and you’d like to
move it to <em>/usr/local/passenger/</em>, then do this:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Run the following command:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>mv /opt/passenger /usr/local/passenger</tt></pre>
</div></div>
</li>
<li>
<p>
Edit your Apache configuration file, and set:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>PassengerRoot /usr/local/passenger</tt></pre>
</div></div>
</li>
</ol></div>
<h3 id="_installing_multiple_ruby_on_rails_versions">8.5. Installing multiple Ruby on Rails versions</h3><div style="clear:left"></div>
<div class="paragraph"><p>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:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>gem install rails -v X.X.X</tt></pre>
</div></div>
<div class="paragraph"><p>where <em>X.X.X</em> is the version number of Ruby on Rails.</p></div>
<div class="paragraph"><p>All of these versions will exist in parallel, and will not conflict with each
other. Phusion Passenger will automatically make use of the correct version.</p></div>
<h3 id="_making_the_application_restart_after_each_request">8.6. Making the application restart after each request</h3><div style="clear:left"></div>
<div class="paragraph"><p>In some situations it might be desirable to restart the web application after
each request, for example when developing a non-Rails application that doesn’t
support code reloading, or when developing a web framework.</p></div>
<div class="paragraph"><p>To achieve this, simply create the file <em>tmp/always_restart.txt</em> in your
application’s root folder. Unlike <em>restart.txt</em>, Phusion Passenger does not
check for this file’s timestamp: Phusion Passenger will always restart the
application, as long as <em>always_restart.txt</em> exists.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">If you’re just developing a Rails application then you probably don’t need
this feature. If you set <em>RailsEnv development</em> in your Apache configuration,
then Rails will automatically reload your application code after each request.
<em>always_restart.txt</em> is only useful if you’re working on Ruby on Rails itself,
or when you’re not developing a Rails application and your web framework
does not support code reloading.</td>
</tr></table>
</div>
<h3 id="sub_uri_deployment_uri_fix">8.7. How to fix broken images/CSS/JavaScript URIs in sub-URI deployments</h3><div style="clear:left"></div>
<div class="paragraph"><p>Some people experience broken images and other broken static assets when they
deploy their application to a sub-URI (i.e. <em>http://mysite.com/railsapp/</em>).
The reason for this usually is that you used a
static URI for your image in the views. This means your <em>img</em> source probably refers
to something like <em>/images/foo.jpg</em>. The leading slash means that it’s an absolute URI:
you’re telling the browser to always load <em>http://mysite.com/images/foo.jpg</em> no
matter what. The problem is that the image is actually at
<em>http://mysite.com/railsapp/images/foo.jpg</em>. There are two ways to fix this.</p></div>
<div class="paragraph"><p>The first way (not recommended) is to change your view templates to refer to
<em>images/foo.jpg</em>. This is a relative URI: note the lack of a leading slash). What
this does is making the path relative to the current URI. The problem is that if you
use restful URIs, then your images will probably break again when you add a level to
the URI.
For example, when you’re at <em>http://mysite.com/railsapp</em> the browser will look for
<em>http://mysite.com/railsapp/images/foo.jpg</em>. But when you’re at
<em>http://mysite.com/railsapp/controller</em>. the browser will look for
<em>http://mysite.com/railsapp/controller/images/foo.jpg</em>.
So relative URIs usually don’t work well with layout templates.</p></div>
<div class="paragraph"><p>The second and highly recommended way is to always use Rails helper methods to
output tags for static assets. These helper methods automatically take care
of prepending the base URI that you’ve deployed the application to. For images
there is <tt>image_tag</tt>, for JavaScript there is <tt>javascript_include_tag</tt> and for
CSS there is <tt>stylesheet_link_tag</tt>. In the above example you would simply remove
the <em><img></em> HTML tag and replace it with inline Ruby like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><%= image_tag("foo.jpg") %></tt></pre>
</div></div>
<div class="paragraph"><p>This will generate the proper image tag to <tt>$RAILS_ROOT/public/images/foo.jpg</tt>
so that your images will always work no matter what sub-URI you’ve deployed to.</p></div>
<div class="paragraph"><p>These helper methods are more valuable than you may think. For example they also
append a timestamp to the URI to better facilitate HTTP caching. For more information,
please refer to
<a href="http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html">the Rails API docs</a>.</p></div>
<h3 id="_x_sendfile_support">8.8. X-Sendfile support</h3><div style="clear:left"></div>
<div class="paragraph"><p>Phusion Passenger does not provide X-Sendfile support by itself. Please install
<a href="http://tn123.ath.cx/mod_xsendfile/">mod_xsendfile</a> for X-Sendfile support.</p></div>
<h3 id="_upload_progress">8.9. Upload progress</h3><div style="clear:left"></div>
<div class="paragraph"><p>Phusion Passenger does not provide upload progress support by itself. Please
try drogus’s <a href="http://github.com/drogus/apache-upload-progress-module/tree/master">
Apache upload progress module</a> instead.</p></div>
</div>
<h2 id="_under_the_hood">9. Under the hood</h2>
<div class="sectionbody">
<div class="paragraph"><p>Phusion Passenger hides a lot of complexity for the end user (i.e. the web server
system administrator), but sometimes it is desirable to know what is going on.
This section describes a few things that Phusion Passenger does under the hood.</p></div>
<h3 id="_static_assets_serving">9.1. Static assets serving</h3><div style="clear:left"></div>
<div class="paragraph"><p>Phusion Passenger accelerates serving of static files. This means that, if an URI
maps to a file that exists, then Phusion Passenger will let Apache serve that file
directly, without hitting the web application.</p></div>
<div class="paragraph"><p>Phusion Passenger does all this without the need for any mod_rewrite rules. People
who are switching from an old Mongrel-based setup might have mod_rewrite rules such
as these:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt># Check whether this request has a corresponding file; if that
# exists, let Apache serve it, otherwise forward the request to
# Mongrel.
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ balancer://mongrel%{REQUEST_URI} [P,QSA,L]</tt></pre>
</div></div>
<div class="paragraph"><p>These kind of mod_rewrite rules are no longer required, and you can safely remove
them.</p></div>
<h3 id="_page_caching_support">9.2. Page caching support</h3><div style="clear:left"></div>
<div class="paragraph"><p>For each HTTP request, Phusion Passenger will automatically look for a corresponding
page cache file, and serve that if it exists. It does this by appending ".html" to
the filename that the URI normally maps to, and checking whether that file exists.
This check occurs after checking whether the original mapped filename exists (as part
of static asset serving). All this is done without the need for special mod_rewrite
rules.</p></div>
<div class="paragraph"><p>For example, suppose that the browser requests <em>/foo/bar</em>.</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Phusion Passenger will first check whether this URI maps to a static file, i.e.
whether the file <em>foo/bar</em> exists in the web application’s <em>public</em> directory.
If it does then Phusion Passenger will serve this file through Apache immediately.
</p>
</li>
<li>
<p>
If that doesn’t exist, then Phusion Passenger will check whether the file
<em>foo/bar.html</em> exists. If it does then Phusion Passenger will serve this file
through Apache immediately.
</p>
</li>
<li>
<p>
If <em>foo/bar.html</em> doesn’t exist either, then Phusion Passenger will forward the
request to the underlying web application.
</p>
</li>
</ol></div>
<div class="paragraph"><p>Note that Phusion Passenger’s page caching support doesn’t work if your web
application uses a non-standard page cache directory, i.e. if it doesn’t cache to
the <em>public</em> directory. In that case you’ll need to use mod_rewrite to serve such
page cache files.</p></div>
<h3 id="application_detection">9.3. How Phusion Passenger detects whether a virtual host is a web application</h3><div style="clear:left"></div>
<div class="paragraph"><p>After you’ve read the deployment instructions you might wonder how Phusion Passenger
knows that the DocumentRoot points to a web application that Phusion Passenger is
able to serve, and how it knows what kind of web application it is (e.g. Rails or Rack).</p></div>
<div class="paragraph"><p>Phusion Passenger checks whether the virtual host is a Rails application by checking
whether the following file exists:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>dirname(DocumentRoot) + "/config/environment.rb"</tt></pre>
</div></div>
<div class="paragraph"><p>If you’re not a programmer and don’t understand the above pseudo-code snippet, it means
that Phusion Passenger will:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Extract the parent directory filename from the value of the DocumentRoot directory.
</p>
</li>
<li>
<p>
Append the text "/config/environment.rb" to the result, and check whether the resulting
filename exists.
</p>
</li>
</ol></div>
<div class="paragraph"><p>So suppose that your document root is <em>/webapps/foo/public</em>. Phusion Passenger will check
whether the file <em>/webapps/foo/config/environment.rb</em> exists.</p></div>
<div class="paragraph"><p>Note that Phusion Passenger does <strong>not</strong> resolve any symlinks in the document root path by
default since version 2.2.0 — in contrast to versions earlier than 2.2.0, which do resolve
symlinks.
So for example, suppose that your DocumentRoot points to <em>/home/www/example.com</em>, which in
turn is a symlink to <em>/webapps/example.com/public</em>. In versions earlier than 2.2.0, Phusion
Passenger will check whether <em>/webapps/example.com/config/environment.rb</em> exists because it
resolves all symlinks. Phusion Passenger 2.2.0 and later however will check for
<em>/home/www/config/environment.rb</em>. This file of course doesn’t exist, and as a result Phusion
Passenger will not activate itself for this virtual host, and you’ll most likely see an Apache
mod_dirindex directory listing.</p></div>
<div class="paragraph"><p>If you need the old symlink-resolving behavior for whatever reason, then you can turn on
<a href="#PassengerResolveSymlinksInDocumentRoot">PassengerResolveSymlinksInDocumentRoot</a>.</p></div>
<div class="paragraph"><p>Another way to solve this situation is to explicitly tell Phusion Passenger what the
correct application root is through the <a href="#PassengerAppRoot">PassengerAppRoot</a> configuration
directive.</p></div>
<div class="paragraph"><p>Autodetection of Rack applications happens through the same mechanism, exception that
Phusion Passenger will look for <em>config.ru</em> instead of <em>config/environment.rb</em>.</p></div>
</div>
<h2 id="_appendix_a_about_this_document">10. Appendix A: About this document</h2>
<div class="sectionbody">
<div class="paragraph"><p>The text of this document is licensed under the
<a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons
Attribution-Share Alike 3.0 Unported License</a>.</p></div>
<div class="paragraph"><p><span class="image">
<a class="image" href="http://creativecommons.org/licenses/by-sa/3.0/">
<img src="images/by_sa.png" alt="images/by_sa.png" />
</a>
</span></p></div>
<div class="paragraph"><p>Phusion Passenger is brought to you by <a href="http://www.phusion.nl/">Phusion</a>.</p></div>
<div class="paragraph"><p><span class="image">
<a class="image" href="http://www.phusion.nl/">
<img src="images/phusion_banner.png" alt="images/phusion_banner.png" />
</a>
</span></p></div>
<div class="paragraph"><p>Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.</p></div>
</div>
<h2 id="_appendix_b_terminology">11. Appendix B: Terminology</h2>
<div class="sectionbody">
<h3 id="application_root">11.1. Application root</h3><div style="clear:left"></div>
<div class="paragraph"><p>The root directory of an application that’s served by Phusion Passenger.</p></div>
<div class="paragraph"><p>In case of Ruby on Rails applications, this is the directory that contains
<em>Rakefile</em>, <em>app/</em>, <em>config/</em>, <em>public/</em>, etc. In other words, the directory
pointed to by <tt>RAILS_ROOT</tt>. For example, take the following directory structure:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>/apps/foo/ <------ This is the Rails application's application root!
|
+- app/
| |
| +- controllers/
| |
| +- models/
| |
| +- views/
|
+- config/
| |
| +- environment.rb
| |
| +- ...
|
+- public/
| |
| +- ...
|
+- ...</tt></pre>
</div></div>
<div class="paragraph"><p>In case of Rack applications, this is the directory that contains <em>config.ru</em>.
For example, take the following directory structure:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>/apps/bar/ <----- This is the Rack application's application root!
|
+- public/
| |
| +- ...
|
+- config.ru
|
+- ...</tt></pre>
</div></div>
<div class="paragraph"><p>In case of Python (WSGI) applications, this is the directory that contains
<em>passenger_wsgi.py</em>. For example, take the following directory structure:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>/apps/baz/ <----- This is the WSGI application's application root!
|
+- public/
| |
| +- ...
|
+- passenger_wsgi.py
|
+- ...</tt></pre>
</div></div>
</div>
<h2 id="spawning_methods_explained">12. Appendix C: Spawning methods explained</h2>
<div class="sectionbody">
<div class="paragraph"><p>At its core, Phusion Passenger is an HTTP proxy and process manager. It spawns
Ruby on Rails/Rack/WSGI worker processes (which may also be referred to as
<em>backend processes</em>), and forwards incoming HTTP request to one of the worker
processes.</p></div>
<div class="paragraph"><p>While this may sound simple, there’s not just one way to spawn worker processes.
Let’s go over the different spawning methods. For simplicity’s sake, let’s
assume that we’re only talking about Ruby on Rails applications.</p></div>
<h3 id="_the_most_straightforward_and_traditional_way_conservative_spawning">12.1. The most straightforward and traditional way: conservative spawning</h3><div style="clear:left"></div>
<div class="paragraph"><p>Phusion Passenger could create a new Ruby process, which will then load the
Rails application along with the entire Rails framework. This process will then
enter an request handling main loop.</p></div>
<div class="paragraph"><p>This is the most straightforward way to spawn worker processes. If you’re
familiar with the Mongrel application server, then this approach is exactly
what mongrel_cluster performs: it creates N worker processes, each which loads
a full copy of the Rails application and the Rails framework in memory. The Thin
application server employs pretty much the same approach.</p></div>
<div class="paragraph"><p>Note that Phusion Passenger’s version of conservative spawning differs slightly
from mongrel_cluster. Mongrel_cluster creates entirely new Ruby processes. In
programmers jargon, mongrel_cluster creates new Ruby processes by forking the
current process and exec()-ing a new Ruby interpreter. Phusion Passenger on the
other hand creates processes that reuse the already loaded Ruby interpreter. In
programmers jargon, Phusion Passenger calls fork(), but not exec().</p></div>
<h3 id="_the_smart_spawning_method">12.2. The smart spawning method</h3><div style="clear:left"></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">Smart spawning is only available for Ruby on Rails applications, not for
Rack applications or WSGI applications.</td>
</tr></table>
</div>
<div class="paragraph"><p>While conservative spawning works well, it’s not as efficient as it could be
because each worker process has its own private copy of the Rails application
as well as the Rails framework. This wastes memory as well as startup time.</p></div>
<div class="paragraph"><p><span class="image">
<img src="images/conservative_spawning.png" alt="Worker processes and conservative spawning" />
</span><br />
<em>Figure: Worker processes and conservative spawning. Each worker process has its
own private copy of the application code and Rails framework code.</em></p></div>
<div class="paragraph"><p>It is possible to make the different worker processes share the memory occupied
by application and Rails framework code, by utilizing so-called
copy-on-write semantics of the virtual memory system on modern operating
systems. As a side effect, the startup time is also reduced. This is technique
is exploited by Phusion Passenger’s <em>smart</em> and <em>smart-lv2</em> spawn methods.</p></div>
<h4 id="_how_it_works">12.2.1. How it works</h4>
<div class="paragraph"><p>When the <em>smart-lv2</em> spawn method is being used, Phusion Passenger will first
create a so-called <em>ApplicationSpawner server</em> process. This process loads the
entire Rails application along with the Rails framework, by loading
<em>environment.rb</em>. Then, whenever Phusion Passenger needs a new worker process,
it will instruct the ApplicationSpawner server to do so. The ApplicationSpawner
server will create a worker new process
that reuses the already loaded Rails application/framework. Creating a worker
process through an already running ApplicationSpawner server is very fast, about
10 times faster than loading the Rails application/framework from scratch. If
the Ruby interpreter is copy-on-write friendly (that is, if you’re running
<a href="#reducing_memory_usage">Ruby Enterprise Edition</a>) then all created worker
processes will share as much common
memory as possible. That is, they will all share the same application and Rails
framework code.</p></div>
<div class="paragraph"><p><span class="image">
<img src="images/smart-lv2.png" alt="images/smart-lv2.png" />
</span><br />
<em>Figure: Worker processes and the smart-lv2 spawn method. All worker processes,
as well as the ApplicationSpawner, share the same application code and Rails
framework code.</em></p></div>
<div class="paragraph"><p>The <em>smart</em> spawn method goes even further, by caching the Rails framework in
another process called the <em>FrameworkSpawner server</em>. This process only loads
the Rails framework, not the application. When a FrameworkSpawner server is
instructed to create a new worker process, it will create a new
ApplicationSpawner to which the instruction will be delegated. All those
ApplicationSpawner servers, as well as all worker processes created by those
ApplicationSpawner servers, will share the same Rails framework code.</p></div>
<div class="paragraph"><p>The <em>smart-lv2</em> method allows different worker processes that belong to the same
application to share memory. The <em>smart</em> method allows different worker
processes - that happen to use the same Rails version - to share memory, even if
they don’t belong to the same application.</p></div>
<div class="paragraph"><p>Notes:</p></div>
<div class="ulist"><ul>
<li>
<p>
Vendored Rails frameworks cannot be shared by different applications, even if
both vendored Rails frameworks are the same version. So for efficiency reasons
we don’t recommend vendoring Rails.
</p>
</li>
<li>
<p>
ApplicationSpawner and FrameworkSpawner servers have an idle timeout just
like worker processes. If an ApplicationSpawner/FrameworkSpawner server hasn’t
been instructed to do anything for a while, it will be shutdown in order to
conserve memory. This idle timeout is configurable.
</p>
</li>
</ul></div>
<h4 id="_summary_of_benefits">12.2.2. Summary of benefits</h4>
<div class="paragraph"><p>Suppose that Phusion Passenger needs a new worker process for an application
that uses Rails 2.2.1.</p></div>
<div class="ulist"><ul>
<li>
<p>
If the <em>smart-lv2</em> spawning method is used, and an ApplicationSpawner server
for this application is already running, then worker process creation time is
about 10 times faster than conservative spawning. This worker process will also
share application and Rails framework code memory with the ApplicationSpawner
server and the worker processes that had been spawned by this ApplicationSpawner
server.
</p>
</li>
<li>
<p>
If the <em>smart</em> spawning method is used, and a FrameworkSpawner server for
Rails 2.2.1 is already running, but no ApplicationSpawner server for this
application is running, then worker process creation time is about 2 times
faster than conservative spawning. If there is an ApplicationSpawner server
for this application running, then worker process creation time is about 10
times faster. This worker process will also share application and Rails
framework code memory with the ApplicationSpawner and FrameworkSpawner
servers.
</p>
</li>
</ul></div>
<div class="paragraph"><p>You could compare ApplicationSpawner and FrameworkSpawner servers with stem
cells, that have the ability to quickly change into more specific cells (worker
process).</p></div>
<div class="paragraph"><p>In practice, the smart spawning methods could mean a memory saving of about 33%,
assuming that your Ruby interpreter is <a href="#reducing_memory_usage">copy-on-write friendly</a>.</p></div>
<div class="paragraph"><p>Of course, smart spawning is not without gotchas. But if you understand the
gotchas you can easily reap the benefits of smart spawning.</p></div>
<h3 id="_smart_spawning_gotcha_1_unintential_file_descriptor_sharing">12.3. Smart spawning gotcha #1: unintential file descriptor sharing</h3><div style="clear:left"></div>
<div class="paragraph"><p>Because worker processes are created by forking from an ApplicationSpawner
server, it will share all file descriptors that are opened by the
ApplicationSpawner server. (This is part of the semantics of the Unix
<em>fork()</em> system call. You might want to Google it if you’re not familiar with
it.) A file descriptor is a handle which can be an opened file, an opened socket
connection, a pipe, etc. If different worker processes write to such a file
descriptor at the same time, then their write calls will be interleaved, which
may potentially cause problems.</p></div>
<div class="paragraph"><p>The problem commonly involves socket connections that are unintentially being
shared. You can fix it by closing and reestablishing the connection when Phusion
Passenger is creating a new worker process. Phusion Passenger provides the API
call <tt>PhusionPassenger.on_event(:starting_worker_process)</tt> to do so. So you
could insert the following code in your <em>environment.rb</em>:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.11.1
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
<span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
<span style="color: #990000">...</span> code to reestablish socket connections here <span style="color: #990000">...</span>
<span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
<div class="paragraph"><p>Note that Phusion Passenger automatically reestablishes the connection to the
database upon creating a new worker process, which is why you normally do not
encounter any database issues when using smart spawning mode.</p></div>
<h4 id="_example_1_memcached_connection_sharing_harmful">12.3.1. Example 1: Memcached connection sharing (harmful)</h4>
<div class="paragraph"><p>Suppose we have a Rails application that connects to a Memcached server in
<em>environment.rb</em>. This causes the ApplicationSpawner to have a socket connection
(file descriptor) to the Memcached server, as shown in the following figure:</p></div>
<div class="literalblock">
<div class="content">
<pre><tt>+--------------------+
| ApplicationSpawner |-----------[Memcached server]
+--------------------+</tt></pre>
</div></div>
<div class="paragraph"><p>Phusion Passenger then proceeds with creating a new Rails worker process, which
is to process incoming HTTP requests. The result will look like this:</p></div>
<div class="literalblock">
<div class="content">
<pre><tt>+--------------------+
| ApplicationSpawner |------+----[Memcached server]
+--------------------+ |
|
+--------------------+ |
| Worker process 1 |-----/
+--------------------+</tt></pre>
</div></div>
<div class="paragraph"><p>Since a <em>fork()</em> makes a (virtual) complete copy of a process, all its file
descriptors will be copied as well. What we see here is that ApplicationSpawner
and Worker process 1 both share the same connection to Memcached.</p></div>
<div class="paragraph"><p>Now supposed that your site gets Slashdotted and Phusion Passenger needs to
spawn another worker process. It does so by forking ApplicationSpawner. The
result is now as follows:</p></div>
<div class="literalblock">
<div class="content">
<pre><tt>+--------------------+
| ApplicationSpawner |------+----[Memcached server]
+--------------------+ |
|
+--------------------+ |
| Worker process 1 |-----/|
+--------------------+ |
|
+--------------------+ |
| Worker process 2 |-----/
+--------------------+</tt></pre>
</div></div>
<div class="paragraph"><p>As you can see, Worker process 1 and Worker process 2 have the same Memcache
connection.</p></div>
<div class="paragraph"><p>Suppose that users Joe and Jane visit your website at the same time. Joe’s
request is handled by Worker process 1, and Jane’s request is handled by Worker
process 2. Both worker processes want to fetch something from Memcached. Suppose
that in order to do that, both handlers need to send a "FETCH" command to Memcached.</p></div>
<div class="paragraph"><p>But suppose that, after worker process 1 having only sent "FE", a context switch
occurs, and worker process 2 starts sending a "FETCH" command to Memcached as
well. If worker process 2 succeeds in sending only one bye, <em>F</em>, then Memcached
will receive a command which begins with "FEF", a command that it does not
recognize. In other words: the data from both handlers get interleaved. And thus
Memcached is forced to handle this as an error.</p></div>
<div class="paragraph"><p>This problem can be solved by reestablishing the connection to Memcached after forking:</p></div>
<div class="literalblock">
<div class="content">
<pre><tt>+--------------------+
| ApplicationSpawner |------+----[Memcached server]
+--------------------+ | |
| |
+--------------------+ | |
| Worker process 1 |-----/| |
+--------------------+ | | <--- created this
X | new
| connection
X <-- closed this |
+--------------------+ | old |
| Worker process 2 |-----/ connection |
+--------------------+ |
| |
+-------------------------------------+</tt></pre>
</div></div>
<div class="paragraph"><p>Worker process 2 now has its own, separate communication channel with Memcached.
The code in <em>environment.rb</em> looks like this:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.11.1
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
<span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
reestablish_connection_to_memcached
<span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
<h4 id="_example_2_log_file_sharing_not_harmful">12.3.2. Example 2: Log file sharing (not harmful)</h4>
<div class="paragraph"><p>There are also cases in which unintential file descriptor sharing is not harmful.
One such case is log file file descriptor sharing. Even if two processes write
to the log file at the same time, the worst thing that can happen is that the
data in the log file is interleaved.</p></div>
<div class="paragraph"><p>To guarantee that the data written to the log file is never interleaved, you
must synchronize write access via an inter-process synchronization mechanism,
such as file locks. Reopening the log file, like you would have done in the
Memcached example, doesn’t help.</p></div>
<h3 id="_smart_spawning_gotcha_2_the_need_to_revive_threads">12.4. Smart spawning gotcha #2: the need to revive threads</h3><div style="clear:left"></div>
<div class="paragraph"><p>Another part of the <em>fork()</em> system call’s semantics is the fact that threads
disappear after a fork call. So if you’ve created any threads in environment.rb,
then those threads will no longer be running in newly created worker process.
You need to revive them when a new worker process is created. Use the
<tt>:starting_worker_process</tt> event that Phusion Passenger provides, like this:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.11.1
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
<span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
<span style="color: #990000">...</span> code to revive threads here <span style="color: #990000">...</span>
<span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
<h3 id="_smart_spawning_gotcha_3_code_load_order">12.5. Smart spawning gotcha #3: code load order</h3><div style="clear:left"></div>
<div class="paragraph"><p>This gotcha is only applicable to the <em>smart</em> spawn method, not the <em>smart-lv2</em>
spawn method.</p></div>
<div class="paragraph"><p>If your application expects the Rails framework to be not loaded during the
beginning of <em>environment.rb</em>, then it can cause problems when an
ApplicationSpawner is created from a FrameworkSpawner, which already has the
Rails framework loaded. The most common case is when applications try to patch
Rails by dropping a modified file that has the same name as Rails’s own file,
in a path that comes earlier in the Ruby search path.</p></div>
<div class="paragraph"><p>For example, suppose that we have an application which has a patched version
of <em>active_record/base.rb</em> located in <em>RAILS_ROOT/lib/patches</em>, and
<em>RAILS_ROOT/lib/patches</em> comes first in the Ruby load path. When conservative
spawning is used, the patched version of <em>base.rb</em> is properly loaded. When
<em>smart</em> (not <em>smart-lv2</em>) spawning is used, the original <em>base.rb</em> is used
because it was already loaded, so a subsequent <tt>require "active_record/base"</tt>
has no effect.</p></div>
</div>
</div>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
Last updated 2010-03-05 10:35:16 CEST
</div>
</div>
</body>
</html>
|