====== Prepare RAILS environment for Redmine with SQLite using RVM ======
* This guide is supposed to make Redmine installation easier
* No garbage, no harm for the system!
* RAILS stuff is installed to /home/redmine/.rvm
* Redmine is installed to /opt/redmine-N.N, where N.N is version of Redmine
===== Prepare environment =====
#!/bin/bash -e
# Define common variables
USERNAME=redmine
WWW_USERNAME=redmine
RUN_WITH_USERNAME="sudo -iu $USERNAME http_proxy=$http_proxy https_proxy=$https_proxy"
# Create user with $USERNAME
id $USERNAME || sudo useradd -rm $USERNAME
# Install apache2
sudo apt-get install apache2
# Install RVM and rvm reqirements
sudo apt-get install curl
curl -L get.rvm.io | $RUN_WITH_USERNAME bash -s stable
# Install packages suggested by rvm-installer (try 'rvm requirements')
sudo apt-get install \
build-essential openssl libreadline6 libreadline6-dev curl \
git-core zlib1g zlib1g-dev libssl-dev libyaml-dev \
libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev \
ncurses-dev automake libtool bison subversion pkg-config
# Prepare environment for Redmine
## Define versions
REDMINE_VERSION=2.2
REDMINE_DIR=/opt/redmine-${REDMINE_VERSION}
RUBY_VERSION=1.9.3
GEM_VERSION=1.8.25
## Checkout Redmine
sudo svn co http://svn.redmine.org/redmine/branches/${REDMINE_VERSION}-stable $REDMINE_DIR
## Prepare directory and permissions for the bundler
sudo mkdir -p $REDMINE_DIR/.bundle
sudo chown $USERNAME:$USERNAME $REDMINE_DIR/.bundle
sudo chown $USERNAME:$USERNAME $REDMINE_DIR # necessary to be able to create Gemfile.lock during installation
## Install packages necessary to build passenger for apache2
sudo apt-get install libcurl4-gnutls-dev apache2-prefork-dev libapr1-dev libaprutil1-dev
## Install packages necessary to build rmagic
sudo apt-get install libmagick++-dev
## Prepare
GEM_INSTALL="gem install --no-rdoc --no-ri"
GEM_VERSION_SHORT=${GEM_VERSION//./}
cat << EOF | $RUN_WITH_USERNAME bash -e
[[ -s "\$HOME/.rvm/scripts/rvm" ]] && source "\$HOME/.rvm/scripts/rvm" && \
rvm install $RUBY_VERSION-gems$GEM_VERSION_SHORT && \
rvm use $RUBY_VERSION-gems$GEM_VERSION_SHORT && \
rvm rubygems $GEM_VERSION && \
rvm gemset create redmine$REDMINE_VERSION && \
rvm use $RUBY_VERSION-gems$GEM_VERSION_SHORT@redmine$REDMINE_VERSION
## Install bundler (to make a process of dependencies instalation easier)
$GEM_INSTALL bundler
## Install passenger
$GEM_INSTALL passenger
## Build passenger
passenger-install-apache2-module -a
## Install necessary gems using bundler
cd $REDMINE_DIR || exit 1
bundle install --without development test mysql
EOF
# Install Redmine
## Fix some permissions
sudo chown root:root $REDMINE_DIR
cd $REDMINE_DIR
sudo mkdir -p tmp public/plugin_assets
sudo chown -R $WWW_USERNAME files log tmp public/plugin_assets db
sudo chmod -R 755 files log tmp public/plugin_assets
sudo chmod 700 db
sudo chmod 600 db/*.sqlite3
===== Launch redmine shell with RVM =====
* Use redmine-shell.sh to prepare for the first start or to upgrade Redmine.
* Usage: redmine-shell.sh ["command"]
* Examples: redmine-shell.sh
redmine-shell.sh "rake generate_secret_token"
redmine-shell.sh "rake db:migrate"
redmine-shell.sh "gem list"
redmine-shell.sh "bundle install"
#!/bin/bash -e
# Define common variables
USERNAME=redmine
# Define core variables
BASHRC=$(dirname $(readlink -f $0))/redmine-shell.bashrc
RUN_WITH_USERNAME="sudo -iu $USERNAME http_proxy=$http_proxy https_proxy=$https_proxy"
# Launch shell
if [[ -z "$@" ]]; then
$RUN_WITH_USERNAME bash --rcfile $BASHRC
else
$RUN_WITH_USERNAME bash -c "source $BASHRC; $@"
fi
# Common variables
REDMINE_VERSION=2.2
GEMSET=ruby-1.9.3-gems1824@redmine2.2
export RAILS_ENV=production
# Define core variables
REDMINE_DIR=/opt/redmine-${REDMINE_VERSION}
# Prepare RVM environment
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
# Select Redmine gemset
rvm $GEMSET
# Go to Redmine directory
cd $REDMINE_DIR
===== Apache configuration example =====
* Place this file to /etc/apache2/sites-available/ (this is just an example generated by 'passenger-install-apache2-module -a', you have to adjust paths for your installation)
ServerName redmine.company.lan
# Passenger
PassengerUser redmine
LoadModule passenger_module /home/redmine/.rvm/gems/ruby-1.9.3-p362-gems1824@redmine2.2/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
PassengerRoot /home/redmine/.rvm/gems/ruby-1.9.3-p362-gems1824@redmine2.2/gems/passenger-3.0.19
PassengerRuby /home/redmine/.rvm/wrappers/ruby-1.9.3-p362-gems1824@redmine2.2/ruby
# Public directory
DocumentRoot /opt/redmine-2.2/public
# This relaxes Apache security settings.
#AllowOverride all
AllowOverride none
# MultiViews must be turned off.
Options -MultiViews
===== Enable redmine site for apache2 =====
# Apache for redmine
sudo a2dissite default
sudo a2ensite redmine
sudo /etc/init.d/apache2 reload
===== Follow official guides for the next steps =====
* Rails environment is installed and configured
* Apache is installed and configured
* Now you should use redmine-shell.sh script and follow official guides:
* to configure Redmine for SQLite database
* to start Redmine
===== Links =====
* Check http://www.redmine.org/projects/redmine/wiki/RedmineInstall for more information
Habrahabr link: http://habrahabr.ru/post/140219/\\
**Tested on Ubuntu 12.04 LTS with Redmine 2.2 stable**
{{tag>rails rvm redmine ubuntu}}