{"id":15,"date":"2006-04-24T13:36:19","date_gmt":"2006-04-24T21:36:19","guid":{"rendered":"http:\/\/blog.danielparnell.com\/?p=15"},"modified":"2006-04-24T16:53:07","modified_gmt":"2006-04-25T00:53:07","slug":"multiple-ruby-on-rails-applications-under-different-folders-served-by-apache-on-mac-os-x","status":"publish","type":"post","link":"https:\/\/blog.danielparnell.com\/?p=15","title":{"rendered":"Multiple ruby on rails applications under different folders served by Apache on Mac OS X"},"content":{"rendered":"<p><span style=\"font-size: 12pt; font-family: Helvetica; \">I&#8217;ve been doing quite a bit of development recently using Ruby on Rails under Mac OS X.  Unfortunately it can be a little tricky to get rails apps deployed nicely under Apache.  The machine I&#8217;m using is an aging G4 with very little RAM so running rails apps in CGI mode is <\/span><span style=\"font-size: 12pt; font-family: Helvetica; font-weight: bold; text-decoration: underline; \">very<\/span><span style=\"font-size: 12pt; font-family: Helvetica; \"> slow<\/span><span style=\"font-size: 12pt; font-family: Helvetica; \">!  Initially I tried FastCGI, but I found it to be unreliable :(\u00c2\u00a0<br \/>After a bit of looking about on the net I came across SCGI ( <\/span><span style=\"font-size: 12pt; font-family: Helvetica; color: #0000ff; \"><a href=\"http:\/\/www.mems-exchange.org\/software\/scgi\/\">http:\/\/www.mems-exchange.org\/software\/scgi\/<\/a><\/span><span style=\"font-size: 12pt; font-family: Helvetica; \"> ) and some code to use it to run rails. apps ( <\/span><span style=\"font-size: 12pt; font-family: Helvetica; color: #0000ff; \"><a href=\"http:\/\/www.zedshaw.com\/projects\/scgi_rails\/\">http:\/\/www.zedshaw.com\/projects\/scgi_rails\/<\/a><\/span><span style=\"font-size: 12pt; font-family: Helvetica; color: #0000ff; \"> <\/span><span style=\"font-size: 12pt; font-family: Helvetica; \">).\u00c2\u00a0<br \/>Installing these pieces is pretty straight forward\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>1. download and install the SCGI apache module\u00c2\u00a0<br \/>2. install the cmdparse gem (<\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; \">sudo gem install cmdparse<\/span><span style=\"font-size: 12pt; font-family: Helvetica; \">)\u00c2\u00a0<br \/>3. install the highline gem (<\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; \">sudo gem install highline<\/span><span style=\"font-size: 12pt; font-family: Helvetica; \">)\u00c2\u00a0<br \/>4. install the SCGI rails runner\u00c2\u00a0<br \/>5. configure your rails apps for SCGI by executing <\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; font-weight: bold; \">scgi_ctrl config<\/span><span style=\"font-size: 12pt; font-family: Helvetica; \"> in each rails app root folder\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>Make sure that each of your rails apps has a different port selected in the config\/scgi.yaml file\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>Next we need to update <\/span><span style=\"font-size: 12pt; font-family: Helvetica; \">the Apache config file \/etc\/httpd\/httpd.conf<\/span><span style=\"font-size: 12pt; font-family: Helvetica; \">\u00c2\u00a0<br \/>\u00c2\u00a0<br \/><\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; \">LoadModule scgi_module        libexec\/httpd\/mod_scgi.so\u00c2\u00a0<br \/>AddModule mod_scgi.c\u00c2\u00a0<br \/><\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; \">\u00c2\u00a0<br \/><\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; \">&lt;IfModule mod_scgi.c&gt;\u00c2\u00a0<br \/>&nbsp;&nbsp;# matches locations with a dot following at least one more characters, that is,\u00c2\u00a0<br \/>&nbsp;&nbsp;# things like   *,html, *.css, *.js, which should be delivered directly from\u00c2\u00a0<br \/>&nbsp;&nbsp;# the filesystem\u00c2\u00a0<br \/>&nbsp;&nbsp;&lt;locationmatch \\..+$&gt;\u00c2\u00a0<br \/>&nbsp;&nbsp;&nbsp;&nbsp;# don&#8217;t handle those with SCGI\u00c2\u00a0<br \/>&nbsp;&nbsp;&nbsp;&nbsp;SCGIHandler Off\u00c2\u00a0<br \/>&nbsp;&nbsp;&lt;\/locationmatch&gt;  \u00c2\u00a0<br \/>&lt;\/IfModule&gt;\u00c2\u00a0<br \/><\/span><span style=\"font-size: 12pt; font-family: Helvetica; \">\u00c2\u00a0<br \/><\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; \">Alias \/app1 &#8220;\/Library\/WebServer\/RailsApps\/app1\/public&#8221;\u00c2\u00a0<br \/>SCGIMount \/tbgmon 127.0.0.1:9999\u00c2\u00a0<br \/>&lt;directory &#8220;\/Library\/WebServer\/RailsApps\/app1\/public&#8221;&gt;\u00c2\u00a0<br \/>&nbsp;&nbsp;Options +FollowSymLinks\u00c2\u00a0<br \/>&nbsp;&nbsp;Order allow,deny\u00c2\u00a0<br \/>&nbsp;&nbsp;allow from all\u00c2\u00a0<br \/>&lt;\/directory&gt;\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>Alias \/app2 &#8220;\/Library\/WebServer\/RailsApps\/app2\/public&#8221;\u00c2\u00a0<br \/>SCGIMount \/app2 127.0.0.1:9998\u00c2\u00a0<br \/>&lt;Directory &#8220;\/Library\/WebServer\/RailsApps\/app2\/public&#8221;&gt;\u00c2\u00a0<br \/>&nbsp;&nbsp;Options +FollowSymLinks\u00c2\u00a0<br \/>&nbsp;&nbsp;Order allow,deny\u00c2\u00a0<br \/>&nbsp;&nbsp;Allow from all\u00c2\u00a0<br \/>&lt;\/Directory&gt;<\/span><span style=\"font-size: 12pt; font-family: Helvetica; color: #0000df; \">\u00c2\u00a0<br \/><\/span><span style=\"font-size: 12pt; font-family: Helvetica; \">\u00c2\u00a0<br \/>Now we start each of the SCGI server processes by running the <\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; font-weight: bold; \">scgi_ctrl start<\/span><span style=\"font-size: 12pt; font-family: Helvetica; \"> command in each rails app root folder, bounce apache using <\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; font-weight: bold; \">sudo apachectrl graceful<\/span><span style=\"font-size: 12pt; font-family: Helvetica; \"> and the rails apps should be up and running from <\/span><span style=\"font-size: 12pt; font-family: Helvetica; color: #0000ff; \"><a href=\"http:\/\/localhost\/app1\/\">http:\/\/localhost\/app1\/<\/a><\/span><span style=\"font-size: 12pt; font-family: Helvetica; \"> and <\/span><span style=\"font-size: 12pt; font-family: Helvetica; color: #0000ff; \"><a href=\"http:\/\/localhost\/app2\/\">http:\/\/localhost\/app2\/<\/a><\/span><span style=\"font-size: 12pt; font-family: Helvetica; \">\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>That is only half of the story however.  We need to have the SCGI server processes start when the machine boots.  The way to do this under Mac OS X is to create a startup item.  A startup item consists of a couple of files in a folder under \/Library\/StartupItems.  One is a .plist file and the other is a shell script.\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>Create a folder called SCGI under \/Library\/StartupItems and then create the file StartupParameters.plist with the following content\u00c2\u00a0<br \/>\u00c2\u00a0<br \/><\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; \">{\u00c2\u00a0<br \/>&nbsp;&nbsp;Description     = &#8220;SCGI&#8221;;\u00c2\u00a0<br \/>&nbsp;&nbsp;Provides        = (&#8220;SCGI&#8221;);\u00c2\u00a0<br \/>&nbsp;&nbsp;Uses            = (&#8220;Web Server&#8221;);\u00c2\u00a0<br \/>}<\/span><span style=\"font-size: 12pt; font-family: Helvetica; \">\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>Next create a file called SCGI and paste in this text\u00c2\u00a0<br \/>\u00c2\u00a0<br \/><\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; \">#!\/bin\/sh\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>##\u00c2\u00a0<br \/># SCGI\u00c2\u00a0<br \/>##\u00c2\u00a0<\/p>\n<p>. \/etc\/rc.common<\/span><span style=\"font-size: 10pt; font-family: 'Courier New', monospace; \">\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>StartService ()\u00c2\u00a0<br \/>{\u00c2\u00a0<br \/>\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0echo &#8220;Starting SCGI servers&#8221;\u00c2\u00a0<br \/>\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0<br \/>\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0pushd \/Library\/WebServer\/RailsApps\/app1\/ > \/dev\/null ; \/usr\/bin\/scgi_ctrl start ; popd > \/dev\/null\u00c2\u00a0<br \/>\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0pushd \/Library\/WebServer\/RailsApps\/app2\/ > \/dev\/null ; \/usr\/bin\/scgi_ctrl start ; popd > \/dev\/null\u00c2\u00a0<br \/>}\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>StopService ()\u00c2\u00a0<br \/>{\u00c2\u00a0<br \/>\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0echo &#8220;Stopping SCGI servers&#8221;\u00c2\u00a0<br \/>\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0ps ax | grep scgi | grep ruby | awk &#8216;{print $1}&#8217; | xargs kill\u00c2\u00a0<br \/>}\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>RestartService ()\u00c2\u00a0<br \/>{\u00c2\u00a0<br \/>\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0StopService\u00c2\u00a0<br \/>\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0StartService\u00c2\u00a0<br \/>}\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>RunService &#8220;$1&#8221;<\/span><span style=\"font-size: 12pt; font-family: Helvetica; \">\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>According to the SCGI rails runner docs there is an option to choose the root folder of the rails app, but I couldn&#8217;t get it to work.  I suppose I should contact the author about it one of these days ;)\u00c2\u00a0<br \/>\u00c2\u00a0<br \/>Now with any luck the next time your machine reboots the SCGI servers should be started and Apache should forward requests on to your rails apps.\u00c2\u00a0<br \/><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been doing quite a bit of development recently using Ruby on Rails under Mac OS X. Unfortunately it can be a little tricky to get rails apps deployed nicely under Apache. The machine I&#8217;m using is an aging G4 with very little RAM so running rails apps in CGI mode is very slow! Initially &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.danielparnell.com\/?p=15\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Multiple ruby on rails applications under different folders served by Apache on Mac OS X&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3,8,6],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-mac-os-x","category-rails","category-web","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p561S3-f","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15"}],"version-history":[{"count":0,"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}