Setting up a Redmine site on Ubuntu
Posted by Chris Wed, 27 Feb 2008 16:37:00 GMT
After a variety of headaches setting up a redmine instance on an Ubuntu server, I thought I’d write a quick guide on how to do it quickly.
First step
Install Ubuntu. What flavour you go with is up to you.
Packages from apt
Install packages
as root, run:
aptitude install apache2 ruby rubygems subversion ruby-pkg-tools \
ruby1.8-dev build-essential postgresql libdbd-pg-perl libapache2-svn \
libapache-dbi-perl libapache2-mod-perl2 libdigest-sha1-perlIf you want to go with mysql rather than postgres, you can drop the postgresql and libdbd-pg-perl packages, and install the mysql equivalents, but you’re on your own in setting up the database.
Ruby gems
Install gems
as root, run:
gem install rails mongrel mongrel_cluster postgres-pr --include-dependenciesAdd gems to $PATH
I did this by adding the line:
export PATH=/var/lib/gems/1.8/bin to the end of /etc/profileSet up the database for Redmine to use
Switch to postgres user
as root, run:
su postgresCreate the redmine user
createuser redmine --no-superuser --no-createdb --no-createrole --login --pwprompt --encryptedCreate the redmine database
createdb --owner=redmine --encoding=utf-8 redmineSwitch back
exitFor the tutorial, I’ll be using the password “redmine” for the redmine user.
Redmine itself
For this setup I’ll be using the 0.6 stable branch of redmine via svn, and installing it under /var/www/rails_apps/redmine-0.6
Create the directory and checkout Redmine
mkdir /var/www/rails_apps
cd /var/www/rails_apps
svn co http://redmine.rubyforge.org/svn/branches/0.6-stable redmine-0.6Configure database access
Create the file config/database.yml within the redmine directory with the following contents:
production:
adapter: postgresql
database: redmine
host: localhost
username: redmine
password: redmineBootstrap the database
In the Redmine directory, run:
rake db:migrate RAILS_ENV="production"
rake redmine:load_default_data RAILS_ENV="production"Configure mailing from Redmine
Setting up a mail account for redmine is your own business, then change this section of config/environment.rb:
# SMTP server configuration
config.action_mailer.smtp_settings = {
:address => "127.0.0.1",
:port => 25,
:domain => "somenet.foo",
:authentication => :login,
:user_name => "redmine",
:password => "redmine",
}to this:
# SMTP server configuration
config.action_mailer.smtp_settings = {
:address => "mail.yourdomain.com",
:port => 25,
:domain => "yourdomain.com",
:authentication => :login,
:user_name => "mail_user",
:password => "mail_password"
}or whatever’s appropriate for your setup.
Check that everything’s set up correctly
From the redmine directory run:
mongrel_rails start --environment=productionYou should be able to view the redmine site at localhost:3000 and log in using the username “admin” and password “admin”.
Setting up subversion
Create the repository location
as root:
mkdir /var/svn
chmod 0750 /var/svnServe the repository path through Apache
Enable the necessary Apache modules
as root:
a2enmod dav
a2enmod dav_svn
a2enmod perlConfigure site and delegate authentication to Redmine
Copy the file Redmine.pm from the extra/svn directory in Redmine to /usr/lib/apache2.
Create a file under /etc/apache2/sites-available with an appropriate name (e.g. svn.yourdomain) with the following contents:
<VirtualHost *>
ServerAdmin support@yourdomain
ServerName svn.yourdomain
PerlRequire /usr/lib/apache2/Redmine.pm
<Location /svn>
DAV svn
SVNParentPath "/var/svn"
AuthType Basic
Authname "Redmine Project Tracking"
Require valid-user
PerlAccessHandler Apache::Authn::Redmine::access_handler
PerlAuthenHandler Apache::Authn::Redmine::authen_handler
PerlSetVar dsn DBI:Pg:dbname=redmine;host=localhost
PerlSetVar db_user redmine
PerlSetVar db_pass redmine
</Location>
</VirtualHost>Enable the site and restart apache:
ln -s /etc/apache2/sites-available/svn.yourdomain /etc/apache2/sites-enabled/svn.yourdomain
/etc/init.d/apache2 restartCheck it’s up
Now, if you point your browser to http://svn.yourdomain/svn you should be prompted for a username and password. Don’t worry about authenticating yet, that’s for when you actually have a project repository to go poking around in.
Serve Redmine through apache and mongrel_cluster
Set up the cluster
Create the file config/mongrel_cluster.yml under the Redmine directory with the following contents:
user: root
cwd: /var/www/rails_apps/redmine-0.6
port: "9000"
environment: production
group: root
address: 0.0.0.0
pid_file: log/mongrel.pid
servers: 2Check the cluster works
In the redmine directory, run:
mongrel_rails cluster::startYou should be able to get to Redmine on ports 9000 and 9001 of your server.
Have the cluster start at boot
As root:
mkdir /etc/mongrel_cluster
ln -s /var/www/rails_apps/redmine-0.6/config/mongrel_cluster.yml /etc/mongrel_cluster/redmine.yml
cp /var/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster /etc/init.d
chmod +x /etc/init.d/mongrel_cluster
/usr/sbin/update-rc.d -f mongrel_cluster defaultsInstall some more Apache modules
As root:
a2enmod proxy
a2enmod proxy_http
a2enmod proxy_balancer
a2enmod rewriteConfigure the redmine site through Apache
Create /etc/apache2/sites-available/redmine.yourdomain with the following contents:
<VirtualHost *>
ServerAdmin support@yourdomain
DocumentRoot /var/www/rails_apps/redmine-0.6
ServerName redmine.yourdomain
ErrorLog /var/www/rails_apps/redmine-0.6/log/error.log
ProxyPass /images !
ProxyPass /stylesheets !
ProxyPass /javascripts !
ProxyPass /favicon.ico !
ProxyPass /static !
ProxyPass /holding !
ProxyPass /templates !
ProxyPass / balancer://redmine_cluster
ProxyPreserveHost On
<Proxy balancer://redmine_cluster>
BalancerMember http://127.0.0.1:9000
BalancerMember http://127.0.0.1:9001
</Proxy>
RewriteEngine On
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://redmine_cluster%{REQUEST_URI} [P,QSA,L]
</VirtualHost>Enable the site and restart apache:
ln -s /etc/apache2/sites-available/redmine.yourdomain /etc/apache2/sites-enabled/redmine.yourdomain
/etc/init.d/apache2 restartHave Redmine manage your repositories
Tell Redmine that it’s managing your repositories
In the Redmine site, go to Administration -> Settings. Tick the box labeled “Enable WS for repository management”
Set up automatic repository creation
Check that repository autocreation works
Add a project through Redmine with the identifier “test”
On your SVN server run:
ruby /var/www/rails_apps/redmine-0.6/extra/svn/reposman.rb --redmine redmine.theoru.com --svn-dir /var/svn --owner www-data --url http://svn.theoru.com/svn/You should get the following message:
repository /var/svn/test registered in Redmine with url http://svn.theoru.com/svn/test
repository /var/svn/test createdMake the server do your dirty work for you
Add the following line to /etc/crontab:
10 * * * * root ruby /var/www/rails_apps/redmine-0.6/extra/svn/reposman.rb --redmine redmine.yourdomain --svn-dir /var/svn --owner www-data --url http://svn.yourdomain/svn/Restrict access to Redmine’s web services’ API
Add the following section to /etc/apache2/sites-available/redmine.yourdomain:
<Location /sys>
Order allow,deny
Allow from ip.of.svn.yourdomain
</Location>Restart apache:
/etc/init.d/apache2 restartRelax, it’s done
Redmine and SVN should be happily up and running.
Once an hour, the cron job you set up will check for any newly registered projects and create an SVN repository for each new project at http://svn.yourdomain/svn/#{project_identifier} and register this location with the project.
To allow repository browsing, you will need to add appropriate credentials (e.g. project manager login) to the repository settings of the project.
Enjoy!
