2006-03-28

Wow. I have spent at least the last week trying to get rails to work the way I wanted it to on my Fedora box with Plesk. This morning I finally got it working. You may be very interested in this article if you’re wondering about any of the following:

  • The mysterious Application Error from rails
  • apache2 and Rails
  • Plesk with Rails
  • FastCGI, mod_fastcgi, scgi, fcgi, mod_fcgid, cgi and just about any other cgi related thing you can think of
  • mysql on rails
  • the gem error “checking for mysql_query() in -lmysqlclient… no”
  • the error “no such file to load — openssl”
  • Things working with WebBrick and not with apache

This is particularly written for people fooling around with Apache2 + FastCGI / fcgid / CGI + (maybe) Fedora and Plesk. (I’m not FC2)

I seriously have spent the last week on this.. countless hours.. and im talking over 20. It’s been a real pain in the ass. I’m going to try to document all my pain for you though so that you don’t have to experience it as well.

The story begins

I wanted to move my application from Windows to my Fedora box. I didn’t bother moving the actual app.. i just wanted to make sure that Rails, Apache2, Plesk and FastCGI all played together nicely. I followed the instructions on the rails wiki for Plesk stuff. Couldn’t get anything to work. I couldn’t get rails to show me anything at all except the “Welcome aboard” page. Wouldn’t work with CGI or FastCGI.

Long story short, I managed to get it working with CGI. Score one for me. But honestly - who cares? Well it helped me.. at least I knew it had something to do with Apache. My application worked in WebBrick AND now Apache2. The problem in Plesk was that the domain under which I was developing had “CGI Support” checked under yourdomain.com->Hosting->Setup. How annoying. I don’t actually understand why that fucked it up so much though. Oh well.

gem install mysql

hahaha. oh yes.. just when things couldn’t get much worse. I tried “gem install mysql” and then “gem install mysql — –with-mysql-include=/usr/include/mysql –with-mysql-lib=/usr/lib/mysql”. Of course I got the multiple error messages in both cases “”checking for mysql_query() in -lmysqlclient… no”". How nice. Did some research.. some people suggested compilers.. I double checked directories.. etc etc etc. Anyhow. .somewhere I figured out that the problem was that it couldn’t find mysql.h. Oh right:


cd /usr/lib/ruby/gems/1.8/gems/mysql-2.7
ruby extconf.rb

After some googling and finding unrelated problems I summed up that I didn’t have the mysql libraries I needed! Apparently I needed a separate package despite the fact that mysql was installed and running. So I did “yum install mysql-devel”. Ka-zing - it works.

Jesse Crouch and the three CGIs

Fastcgi (momma cgi), fcgid (baby cgi) and scgi (second cousin twice disowned cgi). Got it running on CGI just fine. But unless you’re just developing - who gives a shit?

FastCGI

The obvious next step!? What do they all tell you? “USE FASTCGI!”. It’s in Agile.. it’s on the wiki.. it’s everywhere. Why would I use anything else? FastCGI was really what took up most of my time. I got error after error trying to work with this thing. Most notably:

Application error:
Rails application failed to start properly

Oh like that means anything here. It could be anything! Anyway.. I did debugging.. installed, reinstalled.. re-make’d.. re-gem’d.. blah blahblahblahblah. I spent days doing this. Something I will share with you though - I tried running the dispatch.fcgi with:

ruby -d public/dispatch.fcgi

I got the error:

no such file to load -- openssl

Of course.. the solution was to yum install openssl-devel and reinstall.. something.. i dunno… i recompiled and re-gem’d everything i imagine.. anyway.. rails found it that time and figured things out. of course it wasn’t that easy.. took me a few minutes.. hours? to figure out.
Also, so you all know.. the “initializer” not found or whatever error.. is common.. and is.. supposed to happen with all dispatch.fcgi’s? Whatever!

Anyway.. so there’s some help if you’re actually nuts enough to try to get rails running with fastcgi on apache2!

SCGI

Tried this one.. dunno where I found it.. it looked interesting and it looked like a good alterantive.. couldn’t get it to work.. abandoned it.. end of story. not trying to dis SCGI, im sure its great.. i know there are a few people that run it and you should probably try it, especially if you’re looking for an alternative to FastCGI.. It’s just kinda one of those things that’s really burried out there, not many instructions for it and you don’t hear it mentioned many places. looks like it might actually become the replacement for fastcgi though one of these days.

fcgid and mod_fcgid

My lifesaver. this is really what got me rolling on rails on plesk rolling with rails rolling rolling rolling.. yeah. ok. I tried fcgid using some help from this blog and quite a few others. I couldn’t get it to work the first time I tried, but eventually I did when I came back to it. I followed those instructions.. mixed them with the ones for the PleskonRails instuctions.. came out like this:

# This file is /etc/httpd/conf.d/fcgi.conf
# doesn't matter what you name it though

LoadModule fcgid_module modules/mod_fcgid.so

<ifmodule mod_fcgid.c>
AddHandler fcgid-script .fcgi
SocketPath /tmp/fastcgi/sock
IdleTimeout 60
ProcessLifeTime 6000
MaxProcessCount 32
DefaultMaxClassProcessCount 2
IPCConnectTimeout 6
IPCCommTimeout 6
</ifmodule>

the mod_fcgid.so file was in place.. but i kept getting “Service Temporarily Unavailable” errors. I had no idea what was going on. The issue of course was the socket file.. i learned this trick while playing around with FastCGI (maybe all those hours were worth it!) - that sometimes apache throws a fit if it can’t write to the files it needs to - usually it tells you this.. of course it didn’t tell me.. i took a wild guess. I ls -l’d the /tmp directory.. apache was the user on /tmp/fastcgi and sock.. why couldn’t it do it? whatever.. i chmod -R 777′d the directory and restarted apache. boomshakalaka. im rolling.

Notes

  • Don’t use FastCGI on Apache2. I’ve heard numerous complaints about the two not cooperating and I’m actually kind of glad I *couldn’t* get FastCGI to work now that I’ve heard all of them - hopefully fcgid won’t give me anything like that.
  • I learned a ton about linux during this process.. I regret all the time it took, but I don’t regret learning all i did.
  • If something won’t compile.. a gem won’t install.. something like that.. it’s likely that you’re missing some library files.. Find out what it’s looking for and look for a whateveritdemands-devel package.. this seems to be especially true on Plesk as a lot of really minimal things get installed since they don’t entirely expect you to be fooling around with the server much via commandline. I didn’t have these same problems on a cPanel server I was on though.
  • Logs are your friends. Use them as much as possible.
    pay attention to error messages.

    and trust me on the sunscreen

  • Rails wiki, Google, Google, Google.. If you’re looking for instructions start with the rails wiki. It’s a fantastic resource.. if you figure anything out on your own that needs to be added - PLEASE ADD IT. It’s a wiki.. you don’t even have to register. If you have problems with what you’re doing.. search the wiki.. Then go to google like hell.

7 Responses to “Rails on Fedora + Plesk Fiasco”

  1. justin Says:

    Thanks for the tips on the install of Rails on Fedora. I too was pulling my hair out by not having the Mysql-devel rpm installed. Really frustrating… Your bullet points at the end are very true. Get the WHATEVER-devel.rpms and FOR SURE check the logs. They just might contain a tidbit of information that will send you on the right path… then again maybe not, but it’s worth the effort. Time to get back to “railing”.

  2. tekproxy Says:

    Hopefully this will help someone…

    If you’re getting “Service Temporarily Unavailable” and strange error messages in your logs that look like this:
    [Mon Apr 10 09:57:13 2006] [error] (13)Permission denied: mod_fcgid: couldn’t bind unix domain socket /var/lib/apache2/fcgid/sock/2725.15
    [Mon Apr 10 09:57:13 2006] [warn] (13)Permission denied: mod_fcgid: spawn process /var/www/localhost/railsapp/public/dispatch.fcgi error

    Then try setting SocketPath to /tmp/fcgidsock. Using chmod on the directory didn’t work, it was only when I set it to /tmp/fcgidsock (like I’ve seen elsewhere).

    If you still get “Service Temporarily Unavailable” but your logs look like this:
    [Mon Apr 10 10:02:39 2006] [notice] mod_fcgid: process /var/www/localhost/railsapp/public/dispatch.fcgi(4163) exit(communication error), get stop signal 15

    You need to increase the value of IPCCommTimeout. You can lower IPCConnectTimeout to something like 2 since that shouldn’t matter if your computer is slow (unless you are using a 14.4kbps modem). Read more on these settings here: http://fastcgi.coremail.cn/doc.htm

  3. Adam Says:

    tekproxy,

    Thanks for the tip! I was having those exact symptoms and a Google search only turned up your comment. You saved me gads of time.

  4. Will Says:

    Don’t forget to DISABLE SELinux (or adjust the policy!). This is what gave me all the

    [error] (13)Permission denied: mod_fcgid: couldn’t bind unix domain socket /tmp/fcgidsock/12345.6

    errors.

  5. Paul Howarth Says:

    I have RPM packages of mod_fcgid for FC4 and FC5 available here:

    http://www.city-fan.org/ftp/contrib/websrv/

    I shall soon be submitting them for inclusion in Fedora Extras.

    The FC5 package includes an SELinux policy module, though I have only tested it with a single FastCGI application (moin). Feedback from users of other applications would be most welcome.

  6. RailsRoller Says:

    I’m in this stage !

    “I couldn’t get rails to show me anything at all except the “Welcome aboard” page. Wouldn’t work with CGI or FastCG”

    And i’m asking could you help please get something configured to run rails on CGI mode.

    Thanks

  7. Fwolf’s Blog » Blog Archive mod_fcgid出现500错误的解决 - Fwolf's Blog Says:

    […] Rails on Fedora + Plesk Fiasco […]

Leave a Reply