Ruby on Rails
RailsOnFedora

Here’s a step-by-step guide for making Rails work with FastCGI? on Fedora Core 3 from scratch. A much simpler approach can be found at [http://linuxweblog.com/ruby-on-rails-install linuxweblog]

I began with a FC3 “Server” install. This tutorial is suitable to get Rails up and running on Apache2 with PostgreSQL

$ sudo yum install gcc
$ sudo yum install httpd-devel readline-devel postgresql php-pgsql zlib-devel apr apr-devel apr-util-devel
$ ./configure
$ sudo make
$ sudo make install

If you are using Apache you will need mod_fcgi, and the FastCGI Development kit; These can be obtained from http://www.fastcgi.com . You will also need ruby-fcgi.

On Fedora Core 5 mod_fastcgi doesn’t compile, because it uses some deprecated symbols that have gone in Apache httpd 2.2. I found the rpm available at http://www.city-fan.org/ftp/contrib/websrv/ to be very helpful.

NB:FastCGI installs to /usr/local/lib, so if it isn’t there already you will need to add /usr/local/lib to /etc/ld.so.conf and run:

$ ldconfig -v

At this point, read INSTALL.AP2. You’ll need to copy Makefile.AP2 to Makefile, and then edit the Makefile.AP2 to point to an Apache base dir, probably /etc/httpd if you have the httpd package installed.

$ sudo make 
$ sudo make install

NB:If you get the following error, install the httpd-devel package:

/usr/local/httpd/build/special.mk: No such file or directory

NB:If you use Apache2.2, and encounter following error:

'ap_null_cleanup' undeclared (first use in this function)

Please apply this patch to fcgi.h:

@@ -73,6 +73,36 @@
 #define ap_reset_timeout(a)
 #define ap_unblock_alarms()

+/* starting with apache 2.2 the backward-compatibility defines for
+ * 1.3 APIs are not available anymore. Define them ourselves here.
+ */
+#ifndef ap_copy_table
+
+#define ap_copy_table apr_table_copy
+#define ap_cpystrn apr_cpystrn
+#define ap_destroy_pool apr_pool_destroy
+#define ap_isspace apr_isspace
+#define ap_make_array apr_array_make
+#define ap_make_table apr_table_make
+#define ap_null_cleanup apr_pool_cleanup_null 
+#define ap_palloc apr_palloc
+#define ap_pcalloc apr_pcalloc
+#define ap_psprintf apr_psprintf
+#define ap_pstrcat apr_pstrcat
+#define ap_pstrdup apr_pstrdup
+#define ap_pstrndup apr_pstrndup
+#define ap_push_array apr_array_push
+#define ap_register_cleanup apr_pool_cleanup_register
+#define ap_snprintf apr_snprintf
+#define ap_table_add apr_table_add
+#define ap_table_do apr_table_do
+#define ap_table_get apr_table_get
+#define ap_table_set apr_table_set
+#define ap_table_setn apr_table_setn
+#define ap_table_unset apr_table_unset
+
+#endif /* defined(ap_copy_table) */
+
 #if (defined(HAVE_WRITEV) && !HAVE_WRITEV && !defined(NO_WRITEV)) || defined WIN32
 #define NO_WRITEV
 #endif

  • Install Ruby # From source: Download Ruby from http://www.ruby-lang.org/ # From RPM: (As of 02/10/2004, 1.8.2-1.FC3.1 packages are required)
    <code>$ sudo yum install ruby
    $ sudo yum install ruby-devel
    $ sudo yum install rdoc
    $ sudo yum install irb</code>
  • Install Rails and all its dependencies
    <code>$ sudo gem install rails</code>
  • Install PostgreSQL bindings
    <code>$ sudo gem install postgres-pr</code>
  • Create a text file at /etc/httpd/conf.d/fastcgi.conf with the following:
<code>LoadModule fastcgi_module modules/mod_fastcgi.so
<IfModule mod_fastcgi.c>
    FastCgiIpcDir /tmp/fcgi_ipc/
    AddHandler fastcgi-script .fcgi
</IfModule></code>
  1. Restart apache with:
    <code>$ /etc/init.d/httpd restart</code>
  1. At this point I followed the directions for Non VHost Installation (now HowToSetTheBaseURLsOfYourRailsApps) and it worked like a champ.
  2. Don’t forget to change in public/.htaccess
    <code>RewriteRule ^(.*)$ /dispatch.cgi?$1 [QSA,L]</code>

    to
    <code>RewriteRule ^(.*)$ /dispatch.fcgi?$1 [QSA,L]</code>

Todo

I’m having to run chmod -R 777 /tmp/fcgi_ipc/ directory to get it to run correctly right now.
I have SELinux turned on to WARN, and it is warning me about access attempts.

Alternatively you can move the User and Group configuration option above the Include conf.d/*.conf configuration in the /etc/httpd/conf/httpd.conf file.

Extra Help

Note: If you have SElinux security on and you don’t know how to configure it, you are probably screwed. To disable completely use: # setenforce 0
Then, in /etc/sysconfig/selinux set SELINUX=permissive.
Then read http://fedora.redhat.com/docs/selinux-faq-fc3/ and figure out how to do this the right way and please post it here.

Here’s a temporary alternative to turning off SELINUX entirely:

(I don’t know what permissions/role you’ll have to be to do this. I was root)

Change to the directory that your Rails project is in (mine was under /var/www/html/rubytest). Then, execute this command:

<code>find ./ -name *cgi -print0 | xargs -0 chcon -h system_u:object_r:httpd_sys_script_exec_t</code>

What this does is changes the SELINUX context of the cgi files to the same as if they were in the cgi-bin directory, thus allowing them to be executable.

There’s probably a more correct way to do this, and these permissions may be reset if an updated apache rpm gets installed (as I have had that reset the security context on files before).
I THINK the “correct” way to do this would be to edit the selinux policy file – Brazen

Credits

thanks to Jarkko Laine
JimVanFleet helped some with the FC3 version.
Robby Russell also helped add a few minor things