Skip to content

Instantly share code, notes, and snippets.

@brunojppb
Last active November 29, 2022 03:19
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunojppb/bb5dbfacdbcb06ce6bd6303329ff2d72 to your computer and use it in GitHub Desktop.
Save brunojppb/bb5dbfacdbcb06ce6bd6303329ff2d72 to your computer and use it in GitHub Desktop.
How to setup Redmine 4 on Ubuntu 18.04

How to setup Redmine 4 on Ubuntu 18.04

Prerequisites:

Full SSH root access or a user with sudo privileges.

Step 1: Connect to your Server

To connect to your server via SSH as the root user, use the following command:

$ ssh root@IP_ADDRESS -p PORT_NUMBER

and replace IP_ADDRESS and PORT_NUMBER with your actual server IP address and SSH port number.

Once logged in, make sure that your server is up-to-date by running the following commands:

$ apt-get update
$ apt-get upgrade

Step 2: Install MySQL

Next, we need to install the MySQL server. Ubuntu 18.04 has the latest stable version of MySQL ready for installation through the pre-installed repositories.

The following command will install the latest MySQL 5.7 server from the official Ubuntu repositories:

$ apt-get install libssl-dev mysql-server

The MySQL server will be started automatically as soon as the installation is completed. You can also enable the MySQL service to automatically start up upon server reboot with the following command:

$ systemctl enable mysql

Run the following command to further secure your installation:

$ mysql_secure_installation

This script will help you to perform important security tasks like setting up a root password, disable remote root login, remove anonymous users, etc. If the script asks for the root password, just press the [Enter] key, as no root password is set by default.

Step 3: Create a Database for Redmine

Next, we need to create a database for our Redmine installation. Log in to your MySQL server with the following command and enter your MySQL root password:

$ mysql -uroot -p

In this section, we will create a new MySQL database:

CREATE DATABASE redmine_db;
GRANT ALL PRIVILEGES ON redmine_db.* TO 'redmine_user'@'localhost' IDENTIFIED BY 'Password';
FLUSH PRIVILEGES;
exit;

Make sure to replace the password Password with a real, strong password.

Step 4: Install Ruby

The easiest way to install Ruby on your Ubuntu 18.04 server is through the apt package manager. The current version in the Ubuntu repositories is 2.5.1 which is the latest stable version of Ruby at the time of writing this tutorial.

Install Ruby with the following command:

$ apt-get install ruby-full

To verify everything is done correctly, use the command ruby --version. The output should be similar to the following:

$ ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]

Step 5: Install Nginx and Passenger

To install Nginx on your Ubuntu 18.04 server, you need to enter the following command:

$ apt-get install nginx

Enable Nginx to start on boot and start the service using these two lines:

$ systemctl start nginx
$ systemctl enable nginx

To install Passenger, an Nginx module, start by installing the necessary package prerequisites:

$ apt-get install dirmngr gnupg apt-transport-https ca-certificates

Import the repository GPG key and enable the “Phusionpassenger” repository:

$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 561F9B9CAC40B2F7
$ add-apt-repository 'deb https://oss-binaries.phusionpassenger.com/apt/passenger bionic main'

Once the repository is enabled, update the packages list and install the Passenger Nginx module with:

$ apt-get update
$ apt-get install libnginx-mod-http-passenger

Step 6: Download and Install Redmine

We need to install the dependencies necessary to build Redmine:

$ apt-get install build-essential libmysqlclient-dev imagemagick libmagickwand-dev

Go to Redmine’s official website and download the latest stable release of the application. At the time of this article being published, the latest version of Redmine is version 4.0.5.

$ wget https://www.redmine.org/releases/redmine-4.0.5.zip -o /opt/redmine.zip

Once the zip archive is downloaded, unpack it to the /opt directory on your server:

$ cd /opt
$ apt-get install unzip
$ unzip redmine.zip
$ mv redmine-4.0.2 /opt/redmine

Now apply the following required file and folder permissions (these are needed in order for Nginx to have access to the files):

$ chown -R www-data:www-data /opt/redmine/
$ chmod -R 755 /opt/redmine/

Configure database settings:

$ cd /opt/redmine/config/
$ cp configuration.yml.example configuration.yml
$ cp database.yml.example database.yml

Open the database.yml file using your preferred text editor and update the username/password details based on the ones you set in Step 3:

$ nano database.yml
production:
  adapter: mysql2
  database: redmine_db
  host: localhost
  username: redmine_user
  password: "Password"
  encoding: utf8

Then save and exit the file.

Step 7: Install Ruby Dependencies, Generate Keys, and Migrate the Database

Navigate to the Redmine directory and install bundler and other Ruby dependencies:

$ cd /opt/redmine/
$ gem install bundler --no-rdoc --no-ri 
$ bundle install --without development test postgresql sqlite

Run the following command to generate the keys and migrate the database:

$ bundle exec rake generate_secret_token
$ RAILS_ENV=production bundle exec rake db:migrate

Step 8: Configure Nginx

Open your preferred text editor and create the following Nginx server block file:

$ nano /etc/nginx/sites-available/redmine.mydomain.com.conf

Add this configuration to your config file:

# Redirect HTTP -> HTTPS
server {
    listen 80;
    server_name www.redmine.mydomain.com redmine.mydomain.com;

    # include snippets/letsencrypt.conf;
    return 301 https://redmine.mydomain.com$request_uri;
}

# Redirect WWW -> NON WWW
server {
    listen 443 ssl http2;
    server_name www.redmine.mydomain.com;
    return 301 https://redmine.mydomain.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name redmine.mydomain.com;

    root /opt/redmine/public;

    # SSL parameters will be injected by Certbot in a later step
    
    # log files
    access_log /var/log/nginx/redmine.mydomain.com.access.log;
    error_log /var/log/nginx/redmine.mydomain.com.error.log;

    passenger_enabled on;
    passenger_min_instances 1;
    client_max_body_size 10m;
}

Remember to replace redmine.mydomain.com with your own custom domain Then save and exit the file.

Step 9: Install SSL Certificates with Let's Encrypt and Certbot

Install certbot:

$ apt-get install certbot python-certbot-nginx

Generate the certificate and configuration for Nginx

$ certbot --nginx

follow the instructions provided by certbot. at the end, the certificate should be installed and verified.

Step 10: Enable NGINX and Redmine

To enable the server configuration that we just created, run the following command:

$ ln -s /etc/nginx/sites-available/redmine.mydomain.com.conf /etc/nginx/sites-enabled/redmine.mydomain.com.conf

Now, check the config file to make sure that there are no syntax errors. Any errors could crash the web server on restart.

$ nginx -t

Output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If there are no errors, you can reload the Nginx config.

Now reload Nginx

$ service nginx reload

Easy Gantt plugin issues

DB Migration issue

@ashrafalzyoud
Copy link

ashrafalzyoud commented Sep 18, 2020

can u put in ubuntu 20.04+ redmine 4.11???

@brunojppb
Copy link
Author

@ashrafalzyoud have you tried on 20.04 following the same instructions?
I would expect nothing will change. Did you have any errors?

@ashrafalzyoud
Copy link

mysql version in ubunto 20.04 its 8.07

@ashrafalzyoud
Copy link

i think u must update the nginx

upstream redmine {
        server 127.0.0.1:8000;
        server 127.0.0.1:8001;
        server 127.0.0.1:8002;
}

server {
        server_name redmine.DOMAIN.TLD;
        root /var/www/redmine/public;

        location / {
                try_files $uri @redmine;
        }

        location @redmine {
                proxy_set_header  X-Forwarded-For $remote_addr;
                proxy_pass http://redmine;
        }
}

@frenchcarfan
Copy link

Thank you! This is work fine with Redmine 4.1.1 on Ubuntu 18.04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment