hi all, for those of you fighting Apache2 / fcgi and rails to try and get a stable config, I have a heavily tested, stable on in production. I also have complete debian instructions which require only a "download and ''compile''" install of rubygems which is a snap. everything else is apt-get. wheee... I love debian.... This assumes: -debian stable (sarge) vanilla install (tested on i386) -you want apache2 running a single site (HUGE caveat... but hey.. this works for that very well...) thanks to all who suggested the FCGI setup, it works very, very well.. If you want to test your rails app for internal server errors (I was getting random ones) - use this script: usage: sh huntFor500.sh <number-of-requests-per-url> # you should make a ''urls.txt'' which has a list # of all fully-qualified URLs you''d like to test # i.e.: # http://dev.example.com/controller/action # http://dev.example.com/controller/action2 # http://dev.example.com/controller/action2 # (any rails master want to give me a little script # that will output a list of valid URLs from # introspection into the local rails app?) for url in `cat urls.txt`; do COUNTER=0 while [ $COUNTER -lt $1 ]; do echo -n ${COUNTER}- curl --silent $url | grep "Internal" let COUNTER=COUNTER+1 done done You''ll see a count printed for each url which will reset when that url is done: 1-2-3-4-5-6-7-8-9-10-1-2-3-4-5-6-7-8-9-10.... etc for 10 requests. 500s are obvious because grep spits out the lines. if you see only numbers, you''re in good shape. ----------------------------------------------- ## # conventions: # -> means "output from a command to the console" # # means a comment ;) # all commands are made path-independent where possible # otherwise the path is noted ## nano /etc/apt/sources.list # make sure you add non-free to the repository line # deb ftp://ftp.debian.org/debian/ stable main non-free apt-get update apt-get update apt-get upgrade -> 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. # great, nothing to do ;) apt-get install aptitude -> aptitude is already the newest version. -> 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. #nice. apt-get install lynx apt-get install curl apt-get install subversion # need the subversion client adduser # for yourself apt-get install debsums apt-get install chkrootkit apt-get install logwatch chmod 770 /usr/bin/cc chmod 770 /usr/bin/gcc* chmod 770 /usr/bin/gcc chmod 770 /usr/bin/wget chmod 770 /usr/bin/curl echo "nospoof on" >> /etc/host.conf nano /etc/cron.daily/chkrootkit # add your email address chmod 755 /etc/cron.daily/chkrootkit nano /etc/cron.daily/01maillogwatch # add your email address chmod 755 /etc/cron.daily/01maillogwatch perl -pi -e ''s/PermitRootLogin yes/PermitRootLogin no/'' /etc/ssh/sshd_config # prevent root remote logins find /etc/apache* -type f -exec perl -pi -e ''s/ServerSignature On/ServerSignature Off/'' {} \; find /var/www -type f -name *.conf -exec perl -pi -e ''s/ServerSignature On/ServerSignature Off/'' {} \; # don''t leak any info you don''t have to update-rc.d -f lpd remove # remove printing services kill 2219 # lpd''s pid ps axf |grep lpd # no output, good, lpd is stopped. apt-get install \ ruby \ ruby1.8 \ ruby1.8-dev \ libruby1.8 \ libreadline-ruby1.8 \ rdoc1.8 \ irb1.8 \ libfcgi0 \ libfcgi-dev apt-get install apache2 a2dismod userdir # disable the userdir module, we''ll never use it. apt-get install libapache2-mod-fastcgi a2enmod fastcgi a2enmod expires a2enmod rewrite # enable fastcgi, rewrite and expires # we need expires for the IE background cache fix # http://dean.edwards.name/my/flicker.html rm /etc/apache2/sites-available/default rm /etc/apache2/sites-enabled/000-default # delete the default site /etc/init.d/apache2 restart # reload to get it running rm -rf /var/www/apache2-default/ # remove standard apache crap # nice debian utilities: # a2dismod (disable an apache module by name, see above for example) # a2enmod (enable a module by name) # very simple - these utils just add and remove symlinks # from /etc/apache2/mods-available to mods-enabled # the same tools exist for "sites" # a2ensite (enable a site by name) # a2dissite (disable a site by name) ln -s /usr/bin/ruby /usr/local/bin/ruby # this is annoying but necessary mkdir /root/rubygems cd /root/rubygems wget http://rubyforge.org/frs/download.php/3700/rubygems-0.8.10.tgz tar -xzf rubygems-0.8.10.tgz cd rubygems-0.8.10 ruby -v -> ruby 1.8.2 (2005-04-11) [i386-linux] # make sure we have 1.8.2 ruby setup.rb -> lots of things are printed very fast -> install is successful gem install fcgi # compile process # this looks scary, but if you examine the warnings # they''re all minor gem install SimpleSearch gem install rails # accept ALL dependencies # it will build docs, this takes a while gem install search_generator gem install ruby_odeum # not strictly necessary, but not bad to have around # if we decide to use it #store a copy of this apache conf in your rails conf directory as APP_NAME_apache.conf --------- BEGIN APACHE CONF SAMPLE ------------- ServerAdmin me-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org ServerSignature Off ServerName example.com DocumentRoot /var/www/APP-NAME/public <Directory /var/www/APP-NAME/public> Order deny,allow AllowOverride All Options +FollowSymLinks +ExecCGI </Directory> AddHandler cgi-script .cgi <IfModule mod_fastcgi.c> # this is already defined by debian # FastCgiIpcDir /tmp/fcgi_ipc/ AddHandler fastcgi-script .fcgi FastCgiServer /var/www/APP-NAME/public/dispatch.fcgi -initial-env RAILS_ENV=production -idle-timeout 60 -processes 15 </IfModule> # Logs CustomLog /var/www/APP-NAME/log/apache_access.log combined ErrorLog /var/www/APP-NAME/log/apache_error.log --------- END APACHE CONF SAMPLE ------------- ln -s /var/www/APP-NAME/config/APP-NAME_apache.conf /etc/apache2/sites-available/APP-NAME # link the conf for the APP-NAME site into apache # so you can control revisions to your apache conf with subversion ;) a2ensite APP-NAME # enable the config /etc/init.d/apache2 restart # restart #bingo, you have a site in 10 minutes # go to the site. # if you have any problems, look here: tail /var/www/APP-NAME/log/apache_error.log ========================== Enjoy. Once I got this all right, I sure as hell did ;) _a -- alex black, founder the turing studio, inc. 510.666.0074 root-16h2cdTTKgpzNNFeSAH1EA@public.gmane.org http://www.turingstudio.com 2600 10th street, suite 635 berkeley, ca 94710
On Jun 22, 2005, at 5:28 PM, alex black wrote:> Enjoy. > > Once I got this all right, I sure as hell did ;) > > _aExcellent and congratulations! - Jason
alex black wrote:> apt-get install \ > ruby \ > ruby1.8 \ > ruby1.8-dev \ > libruby1.8 \ > libreadline-ruby1.8 \ > rdoc1.8 \ > irb1.8 \ > libfcgi0 \ > libfcgi-dev >You could also get rails from sid (http://packages.debian.org/rails). I didn''t allow it to be released with Sarge because IMHO rails is not yet "mature", but all depends are satisfied in Sarge. I do have one question though (out of ignorance since I''m only using webrick :). What is the purpose of the gem install of fcgi? Also, do you know what are the disadvantages of using Apache2+mod_ruby+rails? - Adam
Excellent Howto. It would have been great to know that libapache2-mod-fastcgi was in non-free when I set it up on my server. :) Cheers, -Sam Pohlenz alex black wrote:> > # make sure you add non-free to the repository line > # deb ftp://ftp.debian.org/debian/ stable main non-free > apt-get update > > apt-get install libapache2-mod-fastcgi > > Enjoy. > > Once I got this all right, I sure as hell did ;) > > _a > > >
> I do have one question though (out of ignorance since I''m only using > webrick :). What is the purpose of the gem install of fcgi?there is some magical ruby fcgi glue code which I don''t understand (or care to) ;)> Also, do you know what are the disadvantages of using > Apache2+mod_ruby+rails?no idea, but everyone says use fcgi, even though it''s a pain in the a** :) _a -- alex black, founder the turing studio, inc. 510.666.0074 root-16h2cdTTKgpzNNFeSAH1EA@public.gmane.org http://www.turingstudio.com 2600 10th street, suite 635 berkeley, ca 94710
> no idea, but everyone says use fcgi, even though it''s a pain in the a** > :)In a few bullet points: * You can only run one application per server (i.e. per apache installation) * Every request has a ruby interpreter, so if you''re requesting static content a 20mb process gets it rather than a small one. With fastcgi only rails requests hit the interpreter. -- Cheers Koz
> * You can only run one application per server (i.e. per apache > installation)how can you run multiple apps with one apache install and fastcgi? _a> * Every request has a ruby interpreter, so if you''re requesting static > content a 20mb process gets it rather than a small one. With fastcgi > only rails requests hit the interpreter.tru, tru. -- alex black, founder the turing studio, inc. 510.666.0074 root-16h2cdTTKgpzNNFeSAH1EA@public.gmane.org http://www.turingstudio.com 2600 10th street, suite 635 berkeley, ca 94710
On 6/24/05, alex black <enigma-16h2cdTTKgpzNNFeSAH1EA@public.gmane.org> wrote:> > * You can only run one application per server (i.e. per apache > > installation) > > how can you run multiple apps with one apache install and fastcgi?I believe it''s done with FastCgiServer rather than FastCgiConfig http://wiki.rubyonrails.com/rails/show/FastCGI -- Cheers Koz
Duane Johnson
2005-Jul-01 16:58 UTC
Did anyone find a solution to fcgi internal server errors?
On Jun 22, 2005, at 6:28 PM, alex black wrote:> If you want to test your rails app for internal server errors (I > was getting random ones) - use this script: >Alex, did you find a solution to this problem? I''m getting the same error every once in a while. I''m using this ruby script (based on your shell script) to detect 500 page errors. They seem to be coming up every 50 to 100 pages. #!/usr/local/bin/ruby18 urls = %w(http://filmfury.com http://filmfury.com/browse) magic_word = "reload" for url in urls print url + ": "; $stdout.flush for counter in 1..30 print counter.to_s + "."; $stdout.flush output = `curl --silent #{url} |grep #{magic_word}` print ''[error page]'' unless output.empty? end puts; $stdout.flush end I would follow your debian instructions and do a step-by-step install, but I''m on FreeBSD instead and trying to find the root of this. I''m occasionally getting this in my fastcgi.crash.log: fcgi 68755 terminated by explicit exit And whenever a 500 error page shows up, another line like this gets added to apache''s http error log: [Fri Jul 1 10:42:00 2005] [error] [client 67.50.46.38] FastCGI: incomplete headers (0 bytes) received from server "/home/users/ filmfury/public_html/dispatch.fcgi" With 15 dispatch.fcgi processes running, why would it occasionally be unable to connect to the application? (I''m assuming that that''s what the incomplete headers means) Thanks, Duane Johnson (canadaduane) _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Duane Johnson
2005-Jul-01 17:57 UTC
Re: Did anyone find a solution to fcgi internal server errors?
On Jul 1, 2005, at 10:58 AM, Duane Johnson wrote:> I''m occasionally getting this in my fastcgi.crash.log: > fcgi 68755 terminated by explicit exit > > And whenever a 500 error page shows up, another line like this gets > added to apache''s http error log: > [Fri Jul 1 10:42:00 2005] [error] [client 67.50.46.38] FastCGI: > incomplete headers (0 bytes) received from server "/home/users/ > filmfury/public_html/dispatch.fcgi" > > With 15 dispatch.fcgi processes running, why would it occasionally > be unable to connect to the application? (I''m assuming that that''s > what the incomplete headers means)Some more clues, and some more questions. First, I started to notice that although I have specified -processes 15 in the FastCgiServer directive of the apache/vhosts file, I am getting > 15 dispatch.fcgi processes running when I query via "ps". What''s even stranger is that there seems to be two types of dispatch.fcgi processes: I have three of these: 80 2874 39661 8 4 0 25220 24424 accept S ?? 1:13.21 / usr/local/bin/ruby /home/users/filmfury/public_html/dispatch.fcgi And 15 of these: 80 39773 39661 0 4 0 20480 19412 select S ?? 0:04.30 / usr/local/bin/ruby /home/users/filmfury/application/public/dispatch.fcgi By chance, I had made public_html a symlink to application/public, so both of these dispatch.fcgi files are identical; however, they must be starting up from two different sources, because my FastCgiServer is set like this: FastCgiServer /home/users/filmfury/application/public/dispatch.fcgi - initial-env RAILS_ENV=production -processes 15 -idle-timeout 60 So, why and where is the public_html/dispatch.fcgi getting started? And why does it appear there is a dynamic FastCGI server somewhere dishing out new FastCGI processes? Duane Johnson (canadaduane) _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails