For users who have never used the Ruby on Rails framework, the installation of Redmine can be a bit confusing. So, I made this guide to simplify the installation process for people.
Guide requirements:
Debian 9 (with root access)
NGINX
MySQL or PostgreSQL
Install dependencies
Before you can install Redmine, you’ll first to need to make sure that your system has the required dependencies.
sudo apt-get install curl git libssl-dev libreadline-dev zlib1g-dev imagemagick libmagickwand-dev build-essentials ruby.h
Install Ruby
Download the latest version of Ruby
curl -kLo ~/ruby-2.4.2.tar.gz http://ftp.ruby-lang.org/pub/ruby/2.4/ruby-2.4.2.tar.gz
tar -xzf ~/ruby-2.4.2.tar.gz
cd ~/ruby-2.4.2/
./configure --prefix=/opt/ruby
make
sudo make install
PATH=/opt/ruby/bin:$PATH #vi .bashrc and add this line, then logout from the server and login
ruby -v #make sure it's the right version
Install Bundler
Redmine uses a package manager for Ruby gems called Bundler
gem install bundler
If you’re using MySQL, make sure you have the MySQL client installed
sudo apt-get install libmysqlclient-dev
Or if you’re using PostgreSQL, make sure that you have the PostgreSQL client installed.
sudo apt-get install libpq-dev
Create Redmine user
For security reasons, it’s recommended that you create a new user to run Redmine under.
sudo adduser --disabled-login --gecos 'Redmine Project Management' redmine
sudo su - redmine
Create the database
For MySQL:
CREATE DATABASE redmine CHARACTER SET utf8;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'my_password';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
For PostgreSQL:
apt-get install postgresql
su postgres
psql
postgres=# CREATE ROLE redmine LOGIN ENCRYPTED PASSWORD '<password>' NOINHERIT VALID UNTIL 'infinity';
postgres=# CREATE DATABASE redmine WITH ENCODING='UTF8' OWNER=redmine TEMPLATE template0;
postgres=# q
exit
Install Redmine
Clone the latest version of Redmine from its Git repository
mkdir /var/www/redmine
git clone git://github.com/redmine/redmine.git /var/www/redmine
Modify database config file
Copy config/database.yml.example to config/database.yml and edit it with your server’s settings
cp /var/www/redmine/config/database.yml.example /var/www/redmine/config/database.yml
vi /var/www/redmine/config/database.yml
If you’re using MySQL then edit
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: my_password
If you’re using PostgreSQL then edit
production:
adapter: postgresql
database: <your_database_name>
host: <postgres_host>
username: <postgres_user>
password: <postgres_user_password>
encoding: utf8
Install Passenger + NginxOn Debian 9 (with APT):
Step1: install Passenger packages
These commands will install Passenger + Nginx module through Phusion’s APT repository. At this point we assume that you already have Nginx installed from your system repository. If not, you should do that first before continuing.
#install phusion passenger PGP key and add HTTPS support for APT
sudo apt-get install -y dirmngr gnupg
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
#Add phusion passenger APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger stretch main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
#Install Passenger + Nginx module
sudo apt-get install -y libnginx-mod-http-passenger
Step2: enable the Passenger Nginx module and restart Nginx
Ensure the config files are in-place
if [ ! -f /etc/nginx/modules-enabled/50-mod-http-passenger.conf ]; then sudo ln -s /usr/share/nginx/modules-available/mod-http-passenger.load /etc/nginx/modules-enabled/50-mod-http-passenger.conf ; fi
sudo ls /etc/nginx/conf.d/mod-http-passenger.conf
If you don’t see a file at /etc/nginx/conf.d/mod-http-passenger.conf; then you need to create it yourself and set the passenger_ruby and passenger_root config options. for example:
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/passenger_free_ruby;
When you are finished with this step, restart Nginx:
nginx -s reload
Step3: check installation
After installation, please validate the install by running sudo
/usr/bin/passenger-config validate-install. For example:
sudo /usr/bin/passenger-config validate-install
All checks should pass. If any of the checks do not pass, please follow the suggestions on screen. Finally, check whether Nginx has started the Passenger core processes. Run sudo /usr/sbin/passenger-memory-stats. You should see Nginx processes as well as Passenger processes. For example:
sudo /usr/sbin/passenger-memory-stats
If you do not see any Nginx processes or Passenger processes, then you probably have some kind of installation problem or configuration problem.
Step4: update regularly
Nginx updates, Passenger updates and system updates are delivered through the APT package manager regularly. You should run the following command regularly to keep them up to date:
sudo apt-get update
sudo apt-get upgrade
You do not need to restart Nginx or Passenger after an update, and you also do not need to modify any configuration files after an update. That is all taken care of automatically for you by APT.
Install gems for Redmine
Now we can install the required gems
cd /var/www/redmine
bundle install --without development test
Generate secret token
Generate a secret token for Rails to encrypt cookies
bundle exec rake generate_secret_token
Prepare the database
Create database structure and populate it
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake redmine:load_default_data
Set permissions
cd /var/www/redmine
mkdir -p tmp/pids tmp/sockets public/plugin_assets
chmod -R 755 files log tmp public/plugin_assets
chown -R www-data:www-data /var/www/redmine/
Testing redmine (WEBrick)
cd /var/www/redmine
bin/rails server -e production -b 0.0.0.0
and you can test it through your browser type your ip:3000
Nginx Configuration
server {
listen 80;
server_name redmine.me;
return 301 https://$server_name$request_uri;
root /var/www/redmine/public;
}
server {
listen 443;
server_name redmine.me;
root /var/www/redmine/public;
ssl on;
ssl_certificate /where/your/certificate/is;
ssl_certificate_key /where/your/privatekey/is;
access_log /var/log/nginx/redmine.access.log;
error_log /var/log/nginx/redmine.error.log;
passenger_enabled on;
passenger_ruby /opt/ruby/bin/ruby;
passenger_sticky_sessions on;
client_max_body_size 10m; # Max attachemnt size
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Final step: Restart Nginx
nginx -s reload