I'm using Homebrew as package manager.
Install
Install FastCGI module for Apache.
brew install homebrew/apache/mod_fcgid
You couldn't?
brew tap it.
Install common headers and libraries of FastCGI.
brew install fcgi
Install fcgi Gem
gem install fcgi
Setting
Apache
User's own site files on Mac is below.
/Users/<your name>/Sites
Make your config file on /etc/apache2/users directory. You need root permission.
cd /etc/apache2/users
vi your.conf
<Directory "/Users/<your name>/Sites/">
Options All
AllowOverride All
Order allow,deny
Allow from all
AddHandler cgi-script .cgi
<IfModule fcgid_module>
AddHandler fcgid-script .fcgi
</IfModule>
</Directory>
There is no security. I recommend you more strict configuration. See Apache's docs.
I assumed your CGI excutable file name is *.cgi. Also I think FastCGI is *.fcgi too.
I don't support any language specific extention (like *.rb, *.py ...) currently.
put mod_fcgid into your Apache
LoadModule fcgid_module <path to>/mod_fcgid.so
brew command would tell you where mod_fcgid installed.
You have to add follow line in /private/etc/apache2/httpd.conf
rbenv
If you are using rbenv, you have to set up more configuration (also me).
Most googled sites tell us 'set up envvars file for Apache'. But on Mac, that's not right.
You have to edit '/System/Library/LaunchDaemons/org.apache.httpd.plist'. offcourse you have to edit as root.
sudo vi /System/Library/LaunchDaemons/org.apache.httpd.plist
...
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/var/rbenv/shims:/usr/local/bin:/usr/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
...
You have to tell Apache a PATH where your favorite Ruby executable is. If not, Apache process can not find where your gem files are.
and then, restart apache.
sudo /usr/sbin/apachectl restart
Ruby script with FCGI
Write your Ruby CGI script like this.
require 'fcgi'
...
FCGI.each_cgi do |cgi|
...
end
So I assumed file name of FastCGI executable ends with fcgi suffix and I am enabling FollowSymlinks on Apache setting. As you know, this is not good for better security.