Setting up Redmine on FreeBSD 9.1

Some time ago, I spent the weekend setting up Redmine on a FreeBSD 9.1 VM. There are some subtle and not-so-subtle gotchas that took some nerves and to figure out, so I’ll just post my steps here so nobody else has to go through the trouble of looking for hints:

# Install a fresh FreeBSD 9.1 in a VM (full install)

# Install Apache, MySQL server and some goodies to play with
pkg_add -r ap22-mod_fastcgi fcgi-devkit wget vim-lite zip unzip mysql55-server erlang-mysql hs-haskell-platform git
echo 'mysql_enable=YES' >> /etc/rc.conf
echo 'apache22_enable=YES' >> /etc/rc.conf
/usr/local/etc/rc.d/mysql-server onestart

# Install Ruby 1.9
# Just press Enter whenever a prompt comes up
cd /usr/ports/lang/ruby19
make # Just hit ENTER at prompts
make install
make clean
ln -sf /usr/local/bin/ruby19 /usr/local/bin/ruby

# Install Rubygems for Ruby 1.9
cd /tmp
tar xfz rubygems-1.8.25.tgz
cd rubygems-1.8.25
ruby setup.rb
ln -sf /usr/local/bin/gem19 /usr/local/bin/gem

# Install Rails and the Ruby-MySQL connector
gem install rails
gem install mysql2

# Download and unpack Redmine
mkdir /srv
cd /srv
tar xfz redmine-2.3.2.tar.gz
rm redmine-2.3.2.tar.gz
chown -R www:www redmine-2.3.2

# Setup Redmine for FastCGI
cd redmine-2.3.2/public
mv dispatch.fcgi.example dispatch.fcgi
mv htaccess.fcgi.example .htaccess
perl -pi -e 's/#.*env ruby/#\!\/usr\/local\/bin\/ruby/g' dispatch.fcgi

# Configure database access
cd ../config
mv configuration.yml.example configuration.yml
echo 'production:' > database.yml
echo '  adapter: mysql2' >> database.yml
echo '  database: redmine' >> database.yml
echo '  host: localhost' >> database.yml
echo '  username: redmine' >> database.yml
echo '  password: "hunter2orsomething"' >> database.yml
echo '  encoding: utf8' >> database.yml

# Setup database
echo "CREATE DATABASE redmine CHARACTER SET utf8;" > my.sql
echo "CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'hunter2orsomething';" >> my.sql
echo "GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';" >> my.sql
mysql < my.sql
rm my.sql

# Install whatever stuff Redmine needs to run
cd ..
bundle install --without development test rmagick
rake generate_secret_token
setenv RAILS_ENV production
rake db:migrate
rake redmine:load_default_data
mkdir public/plugin_assets
gem install fcgi -- --with-fcgi-include=/usr/local/include --with-fcgi-lib=/usr/local/lib
echo 'gem "fcgi"' > Gemfile.local
chown -R www:www *

# Tell Apache to load the FastCGI module and where to find Redmine
perl -pi -e 's/#LoadModule fastcgi_module/LoadModule fastcgi_module/g' /usr/local/etc/apache22/httpd.conf
perl -pi -e 's/^DocumentRoot .*$/DocumentRoot "\/srv\/redmine-2.3.2\/public"/g' /usr/local/etc/apache22/httpd.conf

# Tell user to do some manual edits
# TODO: perl script for this
echo 'Modify your /usr/local/etc/apache22/httpd.conf and start apache or reboot:'
echo ''
echo 'FastCgiServer /srv/redmine-2.3.2/public/dispatch.fcgi -idle-timeout 120 -initial-env RAILS_ENV=production -initial-env PATH=/usr/local/bin -initial-env LD_LIBRARY_PATH=/usr/local/lib -processes 2'
echo ''
echo '<Directory /srv/redmine-2.3.2/public>'
echo '   AddHandler fastcgi-script fcgi'
echo '   Order allow,deny'
echo '   Allow from all'
echo '   AllowOverride all'
echo '   Options +FollowSymLinks +ExecCGI'
echo '   RewriteEngine On'
echo '   RewriteCond %{REQUEST_FILENAME} !-f'
echo '   RewriteRule ^(.*)$ dispatch.fcgi'
echo '</Directory>'

# Done!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s