5 min read

Install Redmine 4.1.X on Ubuntu 20.04 LTS with Passenger

Install Redmine 4.1.X on Ubuntu 20.04 LTS with Passenger

This is a tutorial how to install Redmine on Ubuntu 20.04 LTS with Passenger (pure instalation). This guide will help you to set up Redmine on a new Ubuntu 20.04 LTS installation. It's a long way...

Let's get going:

Get your system running, a fresh nice instalation of Ubuntu 20.04 LTS :)

At start install some packages that are going to be used during this installation:

sudo apt update
sudo apt install vim rkhunter ufw make build-essential libcurl4-openssl-dev libssl-dev zlib1g-dev ruby-dev wget imagemagick gpg2 -y
sudo apt-get install imagemagick libmagickwand-dev -y

Install nginx:

sudo apt install nginx -y
sudo apt install curl -y

Install MySQL:

sudo apt install mysql-server mysql-client libmysqlclient-dev -y

Config MySQL (set up a secure installation and use a strong password).

Follow the instructions on screen for the mysql secure installation.

Next,  log in using your new password and create an user and database for redmine.

sudo mysql_secure_installation
sudo mysql -u root -p

Let's set up the UFW firewall (don't turn it on yet, leve it for after the redmine installation)

sudo ufw allow 'Nginx Full'
sudo ufw allow 22

Install CertBot for SSL Certs:

sudo snap install --classic certbot

Install Ruby, rvm, nodejs and do all config (use the user that will have access to redmine files), there is a lot of code over here, just go one by one.

Where you see user_name, that is the user name used by you to control redmine.

Just to let you know, do not install ruby 2.7.0 and 2.7.1,  get <= 2.6.0 OR >= 2.7.2

gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

\curl -sSL https://get.rvm.io -o rvm.sh

cat rvm.sh | bash -s stable --rails

source ~/.rvm/scripts/rvm

rvm get stable --autolibs=enable

rvm use [ input the version number of ruby that you have installed in previouse step ]

sudo usermod -a -G rvm user_name

sudo curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

sudo curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

sudo echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee 
/etc/apt/sources.list.d/yarn.list

sudo apt update

sudo apt install yarn nodejs -y

gem update --system

echo "gem: --no-document" >> ~/.gemrc

gem install rails

I am already tired, are you?

Now let's install passenger module:

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

sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger focal main > /etc/apt/sources.list.d/passenger.list'

sudo apt-get update

sudo apt-get install -y libnginx-mod-http-passenger

Enable the Passenger module and restart nginx:

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

sudo systemctl restart nginx

If all goes well, then you can validate your installation:

sudo passenger-config validate-install

You should see something like:

* Checking whether this Phusion Passenger install is in PATH... ✓
* Checking whether there are no other Phusion Passenger installations... ✓

Now check if nginx has started the passenger core:

sudo passenger-memory-stats

You should see something like:

Version: 5.0.8
Date   : 2015-05-28 08:46:20 +0200
...

---------- Nginx processes ----------
PID    PPID   VMSize   Private  Name
-------------------------------------
12443  4814   60.8 MB  0.2 MB   nginx: master process /usr/sbin/nginx
12538  12443  64.9 MB  5.0 MB   nginx: worker process
### Processes: 3
### Total private dirty RSS: 5.56 MB

----- Passenger processes ------
PID    VMSize    Private   Name
--------------------------------
12517  83.2 MB   0.6 MB    PassengerAgent watchdog
12520  266.0 MB  3.4 MB    PassengerAgent server
12531  149.5 MB  1.4 MB    PassengerAgent logger
...

Install PHP:

sudo apt install php-fpm php-mysql php-xml php7.4-gd php7.4-xml php7.4-zip php7.4-imagick php7.4-dom php7.4-curl -y

Restart nginx:

sudo systemctl restart nginx

So, now we have passenger and nginx set up, time for the domain name for redmine:
First check ruby command that passenger should use:

passenger-config about ruby-command

You should see something like this:

Traceback (most recent call last):
        2: from /usr/local/bin/passenger-config:23:in `<main>'
        1: from /usr/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
/usr/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': can't find gem passenger (>= 0.a) with executable passenger-config (Gem::GemNotFoundException)

Let's create a domain config file and the root directory for redmine:

mkdir /path_where_you_want_the_redmine_files_to_be_stored
sudo cd /etc/nginx/sites-available/
sudo vim your_domain_name.conf

Insert this into the file, remember to change the server_name with your domain name and the root with the path to the public folder in the redmine root directory:

server {
    listen 80;
    server_name your_domain www.your_domain;
    root /var/www/your_domain;

    index index.html index.htm index.php;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
     }

    location ~ /\.ht {
        deny all;
    }

    passenger_enabled on;
    passenger_app_env production;

    location /cable {
      passenger_app_group_name myapp_websocket;
      passenger_force_max_concurrent_requests_per_process 0;
    }

    # Allow uploads up to 100MB in size
    client_max_body_size 100m;

    location ~ ^/(assets|packs) {
      expires max;
      gzip_static on;
    }


}

Now enable the domain config file:

sudo ln -s /etc/nginx/sites-available/your_domain_name.conf /etc/nginx/sites-enabled/

Restart nginx:

sudo systemctl restart nginx

Redmine files (check the redmin.org site for the latest version):

cd directory_from_the_nginx_domain_file_root
wget https://www.redmine.org/releases/redmine-4.1.1.tar.gz
tar zxf redmine-4.1.1.tar.gz
rm redmine-4.1.1.tar.gz
cd redmine-4.1.1
mv * ../
mv .* ../
rm -Rf redmine-4.1.1

Now the install process (you should have an empty database ready for redmine by now):

gem install bundler

Set the connection to the database:

cd root_redmine_directory/config
cp database.yml.example database.yml
vim database.yml

Set the connection (we are using MySQL):

production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine
  password: "my_password" 

Before we go on we need to change the ruby version check in the main Gemfile to accept ruby 2.7 (this is in the root directory of redmine instalation):

vim GemFile

Change this line (and trust me, it will work on ryby 2.7.2, I know...hehe):

ruby '>= 2.3.0', '< 2.7.0' if Bundler::VERSION >= '1.12.0' 

to:

ruby '>= 2.3.0', '< 2.8.0' if Bundler::VERSION >= '1.12.0'

Now we can continue with bundle install, token and structure of the database:

bundle install --without development test
bundle exec rake generate_secret_token
RAILS_ENV=production bundle exec rake db:migrate

Files permissions:

mkdir -p tmp tmp/pdf public/plugin_assets
sudo chown -R your_user:your_user files log tmp public/plugin_assets
sudo chmod -R 755 files log tmp public/plugin_assets

Check the setup by going to your domain name your_domain.com and login into redmine! User: admin Pass: admin

Setting up email notifications using sendmail:

sudo apt install sendmail -y

cd redmine_root_directory
cd config
cp configuration.yml.example configuration.yml
vim configuration.yml

We need to add on the end of the file under production:

production:
  email_delivery:
    delivery_method: :sendmail

Restart nginx:

sudo systemctl restart nginx

Next step SSL cert for the domain:

sudo Certbot --nginx

Follow the instructions on screen to get an SSL cert for your domain.
Please bear in mind that after installing the SSL cert, you will need to go back to the nginx domain config file and add the passenger on setting to the new server section created by Certbot.

Now turn on the new UFW firewall:

sudo ufw enable

THE END ! Enjoy your new Redmine installation on Ubuntu 20.04 LTS with Passenger.