Windows XP, Apache 2 and SCGI Quick Start
October 22, 2005
These are my notes so I remember what I did in the future. Maybe they’ll work for you too. Consider the starting point a working system with XP, Apache2, FastCGI, etc. and the required gems/libs.These are the steps that worked for me.
The various pieces:
-
SCGI Rails 0.4.2
http://www.zedshaw.com/downloads/scgi_rails/scgi_rails-0.4.2.gem -
apache2-mod_scgi-1.7a-win32.zip
http://www.zedshaw.com/downloads/scgi_rails/apache2-mod_scgi-1.7a-win32.zip
Apache2 configuration
Unzip apache2-mod_scgi-1.7a-win32.zip and place the mod_scgi.so in
your Apache’s modules dir.
httpd.conf
Add the line:
LoadModule scgi_module modules/mod_scgi.so
where all the rest of the LoadModules are.
I use virtual hosts so I can run multiple Rail apps in the same Apache. Here’s how I configured one of them for SCGI:
<VirtualHost *>
ServerName foo
DocumentRoot /www/foo/public
SCGIMount / 127.0.0.1:9999
<LocationMatch ..+$>
# don’t handle those with SCGI
SCGIHandler Off
</LocationMatch>
<Directory /www/foo/public/>
Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny
</Directory>
</VirtualHost>
That’s pretty much it for Apache.
Rail app configuration
RAILS_APP/public/.htaccess
You can change things if you want but guess what? It doesn’t really matter. There’s some nice Ruby magic involved. For completeness, I added a couple of lines just so I’d remember….
AddHandler scgi-script .scgi
RewriteRule ^(.*)$ dispatch.scgi [QSA,L]
SCGI config
The gem installed a few things for you. Change to your Rail app dir and do the following to configure your app using the SCGI utils.
Run:
scgi_ctrl config -e development -S
and enter a password. Password is used by the monitoring & config changing tools.
The -e determines what environment to use, the standards apply: development, production, etc.
The -S is very important for Windows users: turns off some stuff that doesn’t work and will prevent SCGI from running.
The config file that scgi_ctrl creates in RAILS_APP/config is called scgi.yaml.
Here’s mine:
–
:logfile: log/scgi.log
:config: config/scgi.yaml
:disable_signals: true
:env: development
:control_url: druby://127.0.0.1:8999
:host: 127.0.0.1
:password: xxxxxxxx
:port: 9999
Pretty much the defaults. Notice how the :port here matches the SCGIMount directive in your httpd.conf from above.
Making it go
Now that you’re all configured, run:
scgi_service
right there in your Rail app dir.
You shouldn’t see anything happen. Not until you get Apache going and start hitting some pages. So do that now.
There are some log files you’ll want to look at to verify things.
In your Apache2 log dir, look for something like this in your error.log:
[Sat Oct 22 09:01:35 2005] [notice] Apache/2.0.55 (Win32) mod_fastcgi/2.4.2 mod_scgi/1.7 configured — resuming normal operations
Should see a mod_scgi entry.
In RAILS_APP/log look at the scgi.log. You should see something like this:
==> scgi.log <==
[INF][7716] POSIX signal control disabled.
[INF][7716] Running in development mode on 127.0.0.1:9999
If you’re seeing those log entries, everything should be working…. Fingers crossed!
If things aren’t working, double check everything’s cool with Apache. Test the config, make sure it can find what it needs. Most of my issues (and the reason for this little howto) stemmed from trying to figure out which of the various combinations of SCGI utils & config files did the right thing.
So thanks to Zed Shaw, Curt Hibbs and the others for making my Rails apps faster and less troublesome.