Redmine on Apache December 19, 2007
Posted by Björn in : software , 5commentsRuby on Rails and Apache, it sounds great but it can be frustrating. It was for me. After hours of trial and error (and Googling) it finally worked. In the spirit of contributing something back to the Redmine project this article summarizes how I got it running through Apache on Mac OS X. I’m also including a few dead ends and things that went wrong. That part that is missing from most of the documentation I found and leads to frustration. That being said, I can’t guarantee a stress-free experience. This is just my own experience with the installation and there can be differences with your particular setup.
What is this Redmine you speak of?
For a bunch of small personal projects I need something to keep track of tasks and documentation. Redmine is a tool for issue tracking and project management I discovered recently.
I’ve been using Trac for a while and I like the idea of including a wiki and interacting with the source repository. I could have installed Trac again but Redmine offers the same features and more. Built-in support for multiple projects on a single database is my personal killer feature. And it’s written in Ruby. Figuring out why people are making such a big fuss about Ruby was still on my to-do list. So I decided to switch.
After checking out the latest version from the Subversion repository it was up and running in no time thanks to the built-in web server. Apparently that’s a Ruby on Rails feature.
A built-in web server is an advantage for quick deployment but because I was already running Apache on port 80 for Subversion, it became a problem. So I decided to put everything on a single server to make it easier to manage. Or so I thought. Making Rails play nice with Apache was a wee bit harder than expected.
What you need
There are a couple of things you need. The good news is that Leopard provides most of it out of the box.
- Ruby: version 1.8 is included with Leopard
- Ruby on Rails: version 1.2.3 is bundled with Leopard
- Subversion: Leopard has 1.4.4
- Apache 2: Leopard again, just enable it in the System Preferences. It also has all the necessary modules.
- MySQL: you can download 5.0.45 for Mac OS X here
- Redmine of course. I used the 0.6.3 release.
- Your favorite terminal and a root shell
- Time…
Getting Redmine
You should set up Redmine using the built-in server first. If something doesn’t work it’s probably not because of the web server. I recommend you get the latest (stable) release straight from Subversion instead of using an archive. I mention this because the archive has DOS line endings, which messes up things. The Redmine Subversion repository uses native line endings so it doesn’t matter. You’ll see what I mean in a minute.
Apache’s document root on Leopard is /Library/WebServer/Documents. To keep it simple we’re going to put Redmine in /Library/WebServer/redmine and link to it. You put it in any directory you want, just make sure Apache has access. I’ll use an SVN export which means there is no version information. If you want to update from SVN regularly you should check out the trunk.
First get the application:
# cd /Library/WebServer/
# svn export http://redmine.rubyforge.org/svn/tags/0.6.3 redmine
If you’re using a tarball and are wondering about the line endings, run the CGI script from the command line. Running a CGI script from the shell is a good trick to get better error messages than what you find in the server logs.
# redmine/public/dispatch.cgi.example
-sh: redmine/public/dispatch.cgi.example: /usr/bin/ruby^M: bad interpreter: No such file or directory
The ^M means the line endings are wrong. Don’t worry about other errors for now. If you skip this check and later see errors in the Apache logs like the one below it’s probably the same thing.
[error] [client 127.0.0.1] Premature end of script headers: dispatch.cgi, referer: http://localhost/redmine/
For the final step you need to create a link to direct Apache to the application. We’re not going to use a virtual host.
# ln -s /Library/WebServer/redmine/public /Library/WebServer/Documents/redmine
More information about using symlinks is available on this wiki page.
Once that’s settled you can set up your database and configure Redmine following these instructions. Or watch the video.
Apache configuration for CGI
Now Redmine works. Time to move it over to Apache. Let’s start with the CGI approach. It may not be the fastest way to run Rails but it’s very basic and the RoR wiki has bit of documentation on it. I have found this is a good way to weed out most of the problems.
Mac OS X stores the Apache configuration in /private/etc/apache2/. In httpd.conf make sure these lines are not commented out.
LoadModule env_module libexec/apache2/mod_env.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule cgi_module libexec/apache2/mod_cgi.so
Next, create a file redmine.conf in /private/etc/apache2/other. By default, anything in that directory is loaded as part of the configuration. This keeps the main httpd.conf clean and the Redmine stuff is easier to find. Note that I say Redmine, and not Ruby on Rails. For another RoR application you’ll need to add a new configuration file. This is what my file looks like:
SetEnv RAILS_ENV production
<Directory "/Library/WebServer/Documents/redmine">
AllowOverride all
Order allow,deny
Allow from all
</Directory>
Note that I refer to /Library/WebServer/Documents/redmine and not /Library/WebServer/redmine/. If you use the wrong directory the AllowOverride directive won’t work. It has to work because Redmine uses an .htaccess file. Some examples also include an AddHandler directive. I have found that it’s not necessary because it’s already taken care of in .htaccess.
Apache is now configured and has to be restarted:
# apachectl restart
Directory permissions
The web server is ready but it can’t do anything yet. First it needs a CGI script. In Redmine’s public directory rename the example script dispatch.cgi.example to dispatch.cgi.
In addition write access is required for the tmp and log directories under /Library/WebServer/redmine. Run chmod 666 on them.
Now you should see Redmine’s home page when you open http://localhost/redmine in your browser.
Route problems
At this point the front page works but you’re could be getting errors when you click on a link.
no route found to match "/account/login" with {:method=>:get}
If, like me, you don’t know Ruby this is very confusing. If you check the Apache error log, you see that there is something wrong with the paths in the Ruby application. Thanks to this blog entry there is a solution. In config/boot.rb replace
root_path = Pathname.new(root_path).cleanpath(true).to_s
with
root_path = Pathname.new(root_path).cleanpath(true).realpath().to_s
Can you make this thing go faster?
Redmine works now but it’s very slow. This is where FastCGI comes in. First disable mod_cgi in httpd.conf and enable mod_fastcgi. FastCGI also needs a temporary directory with full access.
# mkdir /tmp/fcgi_ipc
# chmod 777 /tmp/fcgi_ipc
And then add this to httpd.conf:
<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
</IfModule>
Apache will need a restart again.
You also need to enable
ENV['RAILS_ENV'] ||= 'production'
in redmine/config/environment.rb. For some reason I couldn’t pass the environment variable to FastCGI so it has to be fixed in Ruby.
Browse to your Redmine URL and enjoy the quick response time.
Hooking up Irssi to Growl November 28, 2007
Posted by Björn in : software , 2commentsWhile keeping an Irssi session running in the background it’s good to be notified when someone calls your name. Enter growl.pl, a script that sends out Growl notifications.
It’s not very hard to set up but it requires an extra package. There are some basic instructions on the Growl site. I used Fink to install Irssi which already has Perl support so I could skip the first step.
Get the SDK here if you don’t have the Perl bindings for Growl yet. If Mac-Growl is already installed on your system you can skip this. Load the disk image and go to Bindings/perl/Mac-Growl. To install the module run these commands:
perl Makefile.PL
sudo make
make test
sudo make install
When running the make test line you should get a few test notifications. If that works you can execute the install command. You should read the README file for more information.
Once you have the Perl bindings you need to install the script. Finding it was the hardest part. It’s supposed to come with Growl but it wasn’t clear in which directory it is. Eventually I found it and I’m keeping a copy here for future reference. Put it in ~/.irssi/scripts (or ~/.irssi/scripts/autorun) and load the script in Irssi with /load script growl.pl.
Now you can set up the notification the way you want in Growl. I added a little ping sound to get my attention.
Update: I fixed the link to the script. Make sure you rename it to growl.pl after downloading. I had to strip the extension because Apache wants to execute the script.
Dashboard widget for monitoring an Infrant ReadyNAS November 23, 2007
Posted by Björn in : software, widget , add a commentIf you have a ReadyNAS you should take a look at this thread on the Infrant forums. They have created a widget for Dashboard to monitor the disk arrays on your network. It offers direct links to open the management console or connect over AFP. Very cool.
You may need to use Safari to download it. When I used Firefox the widget was corrupt and couldn’t be installed.
Mobile phone synchronisation on the Mac November 22, 2007
Posted by Björn in : software , add a commentTonight I wondered if I could back up my cell phone contacts to my Mac. On Windows I use Float’s Mobile Agent to control my phone. I don’t use al of it, mainly for managing my contacts and calendar and typing the occasional SMS. It takes ages if I try to do that on the phone’s keypad.
I was pleased to find out that I didn’t need any special software to synchronize my Mac and my phone. After I configured the device via System preferences > Bluetooth > Add device, iSync started, recognized my phone and copied my contacts and calendar to Address Book and iCal. That was easy. This probably doesn’t work with every phone, but I don’t care. Mine (Sony Ericsson T630) is supported
If I could find a way to send SMS messages from my laptop it would be perfect. Any ideas?
Using time machine with a NAS November 20, 2007
Posted by Björn in : backup, software , 2commentsLeopard comes with Time Machine, an integrated backup solution. I’m quite impressed with the way Apple provides a decent backup strategy in such a user friendly manner. Actually, I still have to check how decent the backups really are, but the theory sounds good.
Unfortunately it doesn’t support backing up to network drives. This feature was present in early versions but dropped before release. However, it is possible to enable network support again. It’s not officially supported so if anything goes wrong you’re out of luck. I ‘m going to take the risk and see what happens.
On the Infrant Netgear forums I found a thread telling me how to make Time Machine use my ReadyNAS as a backup destination. If you don’t want to read the whole thread, here’s what I did.
- Create a new share on the NAS and enable AFP
- Execute this command in a terminal (all on 1 line):
defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1 - Run the above command again but this time without typos (hint: copy/paste).
- Browse to the share in Finder (Command-K, afp://server/share)
- Start Time Machine and choose the backup drive. The NAS share should be in the list.
- Let Time Machine do whatver it needs to do. It may look like it hangs at first but it’s preparing the first backup. After a while a progress window will appear.
That’s it. Right now Time Machine is making the first backup of my MacBook. That’s going to take a while because it’s copying 72 GB over a wireless connection. The incremental backups should be a lot smaller. For the next couple of days I’m going to keep a close eye on Time Machine and test its restore abilities. I hope it works as well as it looks good.