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.
$ wget http://fastcgi.com/dist/fcgi-2.4.0.tar.gz $ tar zxvf fcgi-2.4.0.tar.gz $ cd fcgi-2.4.0 $ ./configure $ sudo make $ sudo make install</pre>
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
$ wget http://fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz $ tar zxvf mod_fastcgi-2.4.2.tar.gz $ cd mod_fastcgi-2.4.2
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</pre>
- 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)
$ sudo yum install ruby
$ sudo yum install ruby-devel
$ sudo yum install rdoc
$ sudo yum install irb
- Install rubygems Download “RubyGems”: from http://www.rubyforge.org/
- Install Rails and all its dependencies
$ sudo gem install rails
Bath and Shower
Fragrance
Gift Sets
Hair Care
Makeup
Men’s Grooming
Shaving and Hair Removal
Skin Care
Tools and Accessories
Computers – Computer Add-Ons
Computers – Desktops
Computers – Handhelds & PDAs
Computers – Notebooks
Baby Diapering
Baby Feeding
For Moms
Baby Furniture
Baby Gear
Baby Gifts
Baby Health & Baby Care
Nursery Décor
Potty Training
Baby Safety
Baby Strollers
- Install ruby-fcgi
$ sudo gem install fcgi
Note if the above command does not install fcgi version 0.8.6 or greater then unistall it and install 0.8.6 from http://raa.ruby-lang.org/list.rhtml?name=fcgi manually
- Install PostgreSQL bindings
$ sudo gem install postgres-pr
- Create a text file at
/etc/httpd/conf.d/fastcgi.conf with the following:
LoadModule fastcgi_module modules/mod_fastcgi.so
<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
</IfModule>
- Restart apache with:
$ /etc/init.d/httpd restart
- At this point I followed the directions for Non VHost Installation (now HowToSetTheBaseURLsOfYourRailsApps) and it worked like a champ.
- Don’t forget to change in
public/.htaccess
RewriteRule ^(.*)$ /dispatch.cgi?$1 [QSA,L]
to
RewriteRule ^(.*)$ /dispatch.fcgi?$1 [QSA,L]
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:
find ./ -name *cgi -print0 | xargs -0 chcon -h system_u:object_r:httpd_sys_script_exec_t
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
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.
$ wget http://fastcgi.com/dist/fcgi-2.4.0.tar.gz $ tar zxvf fcgi-2.4.0.tar.gz $ cd fcgi-2.4.0 $ ./configure $ sudo make $ sudo make install</pre>
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
$ wget http://fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz $ tar zxvf mod_fastcgi-2.4.2.tar.gz $ cd mod_fastcgi-2.4.2
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</pre>
- 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)
$ sudo yum install ruby
$ sudo yum install ruby-devel
$ sudo yum install rdoc
$ sudo yum install irb
- Install rubygems Download “RubyGems”: from http://www.rubyforge.org/
- Install Rails and all its dependencies
$ sudo gem install rails
Bath and Shower
Fragrance
Gift Sets
Hair Care
Makeup
Men’s Grooming
Shaving and Hair Removal
Skin Care
Tools and Accessories
Computers – Computer Add-Ons
Computers – Desktops
Computers – Handhelds & PDAs
Computers – Notebooks
Baby Diapering
Baby Feeding
For Moms
Baby Furniture
Baby Gear
Baby Gifts
Baby Health & Baby Care
Nursery Décor
Potty Training
Baby Safety
Baby Strollers
- Install ruby-fcgi
$ sudo gem install fcgi
Note if the above command does not install fcgi version 0.8.6 or greater then unistall it and install 0.8.6 from http://raa.ruby-lang.org/list.rhtml?name=fcgi manually
- Install PostgreSQL bindings
$ sudo gem install postgres-pr
- Create a text file at
/etc/httpd/conf.d/fastcgi.conf with the following:
LoadModule fastcgi_module modules/mod_fastcgi.so
<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
</IfModule>
- Restart apache with:
$ /etc/init.d/httpd restart
- At this point I followed the directions for Non VHost Installation (now HowToSetTheBaseURLsOfYourRailsApps) and it worked like a champ.
- Don’t forget to change in
public/.htaccess
RewriteRule ^(.*)$ /dispatch.cgi?$1 [QSA,L]
to
RewriteRule ^(.*)$ /dispatch.fcgi?$1 [QSA,L]
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:
find ./ -name *cgi -print0 | xargs -0 chcon -h system_u:object_r:httpd_sys_script_exec_t
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