0%

Setup GitLab Redmine MediaWiki on Ubuntu 18.04

Back in 2016, I was asked for setting up GitLab, Redmine, and MediaWiki on a single Linux machine for our development team at work. This blog is just a record for how I built all stuff from scratch. At that time, it was based on Ubuntu 14.04, but in this blog I will go through all the steps based on Ubuntu 18.04.

Due to the compatibility issues on plugins for Redmine that I setup earlier, I will keep its version for now. The other two, GitLab and MediaWiki, will be upgraded to the latest versions (as of 2019).

Goal

Environment

Prerequisite

  • Install basic packages

    1
    2
    sudo apt update
    sudo apt install -y bash-completion nano git curl
  • Update locale on Linux machine

    1
    2
    3
    sudo locale-gen "en_US.UTF-8"
    sudo update-locale LANG=en_US.UTF8
    localectl

Install LAMP

LAMP is an archetypal model of web service stacks, named as an acronym of the names of its original four open-source components: the Linux operating system, the Apache HTTP Server, the MySQL relational database management system (RDBMS), and the PHP programming language.


Following packages are required for setting up Redmine and MediaWiki.

1
2
3
sudo apt install -y apache2 mysql-server php php-mysql libapache2-mod-php php-xml php-mbstring
sudo apt install -y php-apcu php-intl imagemagick inkscape php-gd php-cli php-curl
sudo apt install -y libmagickwand-dev libmysqlclient-dev

Configure and run MySQL

1
2
3
sudo service mysql stop
sudo usermod -d /var/lib/mysql mysql
sudo service mysql start

Add your server domain name to the end of Apache config file /etc/apache2/apache2.conf. For demo purpose, I use localhost here.

1
sudo nano /etc/apache2/apache2.conf

Add ServerName localhost at the end of the file.

Restart the Apache service:

1
sudo service apache2 restart

Reference:
How to install MediaWiki on Debian or Ubuntu

Now your Apache web server should be up and running on http://127.0.0.1 and you should be able to see Apache test page as follow.


Create a phpinfo test page:

1
echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/phpinfo.php

Navigate to http://localhost/phpinfo.php on your browser and you should be able to see outputs information for your PHP’s configuration.

Setup Ruby on Rails

Ruby on Rails, or Rails, is a server-side web application framework written in Ruby under the MIT License. Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and web pages.


Redmine runs on Rails. It is why we need to install Ruby and Rails. Depending on the version of Redmine, you may have different requirements on Ruby and Rails.

For more information, please see:
https://www.redmine.org/projects/redmine/wiki/RedmineInstall

In my case, I am going to install Redmine 3.3.9, so I will have to install Ruby 2.4.x and Rails 4.2.x.

Reference:
https://gorails.com/setup/ubuntu/18.04

Install Ruby

The first step is to install dependencies for Ruby and Rails:

1
2
3
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
1
2
3
4
sudo apt update
sudo apt install -y git-core zlib1g-dev build-essential libssl-dev libreadline-dev \
libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev \
libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn

Then, install Ruby by rbenv:

1
2
3
4
5
cd ~
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
1
2
3
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
1
2
3
rbenv install 2.4.9
rbenv global 2.4.9
ruby -v

Finally, install the latest bundler and rehashes shims.

1
2
gem install bundler
rbenv rehash

Install Rails

1
2
3
gem install rails -v 4.2.11.1
rbenv rehash
rails -v
  • In case if you run into the issue as sprockets requires Ruby version >= 2.5.0., you can install the old version of sprockets by issuing following command:
    1
    gem install sprockets -v 3.7.2

Setup Services

MediaWiki

MediaWiki is a free and open-source wiki engine. It was developed for use on Wikipedia in 2002, and given the name “MediaWiki” in 2003. It remains in use on Wikipedia and almost all other Wikimedia websites, including Wiktionary, Wikimedia Commons and Wikidata; these sites continue to define a large part of the requirement set for MediaWiki. MediaWiki was originally developed by Magnus Manske and improved by Lee Daniel Crocker. Its development has since then been coordinated by the Wikimedia Foundation.

Install MediaWiki

Download MediaWiki source code:

1
2
3
cd ~
wget https://releases.wikimedia.org/mediawiki/1.32/mediawiki-1.32.2.tar.gz
sudo tar zxf mediawiki-1.32.2.tar.gz -C /opt/

In our case, we supposed to have more than one people to manage the services. Therefore, we setup a group so that all users, who are in the same group, will have the same permissions to take care of the services.

1
2
3
sudo groupadd mediawiki
sudo usermod -aG mediawiki jocodoma
logout

Make sure directories and files have correct permissions:

1
2
3
4
5
sudo chown -R root.mediawiki /opt/mediawiki-1.32.2
sudo chown -R www-data.www-data /opt/mediawiki-1.32.2/images/
sudo chmod 2775 /opt/mediawiki-1.32.2/
find /opt/mediawiki-1.32.2/ -type d -exec sudo chmod 2775 {} \;
find /opt/mediawiki-1.32.2/ -type f -exec sudo chmod 0664 {} \;

Create the database for MediaWiki, where the name of database is wikiDB, the owner of the database wikiDB is wikiAdmin, the password of the user wikiAdmin is wikiPassword. You can choose your own DB name and username/password.

1
2
3
4
5
6
# mysql -u root -p  # for Ubuntu 16.04 or before
sudo mysql # for Ubuntu 18.04
CREATE USER 'wikiAdmin'@'localhost' IDENTIFIED BY 'wikiPassword';
CREATE DATABASE wikiDB CHARACTER SET utf8;
GRANT ALL PRIVILEGES ON wikiDB.* TO 'wikiAdmin'@'localhost';
exit

Configure MediaWiki

In order to run in sub-URI, create a symbolic link for MediaWiki under /var/www/html/:

1
sudo ln -s /opt/mediawiki-1.32.2/ /var/www/html/mediawiki

Run http://localhost/mediawiki on your browser, and go through the steps to configure your MediaWiki. LocalSettings.php file will be generated in the end of configuration process.

Below is the changes I made on LocalSettings.php file:

/opt/mediawiki-1.32.2/LocalSettings.php
1
2
3
$wgSitename = "MY_WiKi";
$wgScriptPath = "/mediawiki";
$wgServer = "http://localhost";

For more details on configuration:
https://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Debian_or_Ubuntu

Test

You should be able to see your MediaWiki on http://localhost/mediawiki

Redmine

Redmine is a free and open source, web-based project management and issue tracking tool. It allows users to manage multiple projects and associated subprojects. It features per project wikis and forums, time tracking, and flexible, role-based access control. It includes a calendar and Gantt charts to aid visual representation of projects and their deadlines. Redmine integrates with various version control systems and includes a repository browser and diff viewer.


Reference:
https://www.redmine.org/

Create a group for redmine, and add the user to the group.

1
2
3
sudo groupadd redmine
sudo usermod -aG redmine jocodoma
logout

Download Redmine source code

1
2
3
cd ~
wget http://www.redmine.org/releases/redmine-3.3.9.tar.gz
sudo tar zxf redmine-3.3.9.tar.gz -C /opt/

Make sure directories and files have correct permissions:

1
2
3
4
sudo chown -R root.redmine /opt/redmine-3.3.9
sudo chmod 2775 /opt/redmine-3.3.9/
find /opt/redmine-3.3.9/ -type d -exec sudo chmod 2775 {} \;
find /opt/redmine-3.3.9/ -type f -exec sudo chmod 0664 {} \;

Database connection configuration

1
2
3
4
5
6
# mysql -u root -p  # for Ubuntu 16.04 or before
sudo mysql # for Ubuntu 18.04
CREATE USER 'redmineAdmin'@'localhost' IDENTIFIED BY 'redminePassword';
CREATE DATABASE redmineDB CHARACTER SET utf8;
GRANT ALL PRIVILEGES ON redmineDB.* TO 'redmineAdmin'@'localhost';
exit

As you can see, the name of database is redmineDB, the owner of the database redmineDB is redmineAdmin, the password of the user redmineAdmin is redminePassword.

The above information will be needed for config/database.yml. Here’s my database config file:

/opt/redmine-3.3.9/config/database.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
production:
adapter: mysql2
database: redmineDB
host: localhost
username: redmineAdmin
password: redminePassword
encoding: utf8

#development:
# adapter: mysql2
# database: redmine_development
# host: localhost
# username: root
# password: ""
# encoding: utf8

For more info, please see:
https://www.redmine.org/projects/redmine/wiki/RedmineInstall#Step-3-Database-connection-configuration

Dependencies Installation

Due to the versions of Redmine (v3.3.9) and Ruby (v2.4.6) we use, we need to downgrade the version of bundler for v1.17.3 to be able to install dependencies.

1
2
3
4
5
6
cd /opt/redmine-3.3.9/
gem install mysql2 -v '0.4.10'
# gem install bundler
# RAILS_ENV=production bundle install --without development test
gem install bundler -v 1.17.3
RAILS_ENV=production bundle _1.17.3_ install --without development test

Other Configurations

1
2
3
RAILS_ENV=production bundle exec rake generate_secret_token  # Session store secret generation
RAILS_ENV=production bundle exec rake db:migrate # Database schema objects creation
RAILS_ENV=production bundle exec rake redmine:load_default_data # Database default data set

(Optional) Setup SMTP for Sending Notification E-mails

/opt/redmine-3.3.9/config/configuration.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
# default configuration options for all environments
default:
# Outgoing emails configuration
# See the examples below and the Rails guide for more configuration options:
# http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration

==== Simple SMTP server at localhost

email_delivery:
delivery_method: :smtp
smtp_settings:
address: "10.130.32.33"
port: 25

IP address points to your SMTP server. By default, the port of SMTP should be 25.

Test

In order to run in sub-URI, create a symbolic link for Redmine under /var/www/:

1
sudo ln -s /opt/redmine-3.3.9/ /var/www/redmine

Before we test Redmine, let’s setup GitLab first.

GitLab Community Edition

GitLab is a web-based DevOps lifecycle tool that provides a Git-repository manager providing wiki, issue-tracking and CI/CD pipeline features, using an open-source license, developed by GitLab Inc. The software was created by Dmitriy Zaporozhets and Valery Sizov, and is used by several large tech companies.


Reference:
https://about.gitlab.com/install/#ubuntu

Enable Apache Modules

1
2
3
4
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod rewrite
sudo service apache2 restart

Install Dependencies

1
2
sudo apt update
sudo apt install -y openssh-server ca-certificates

(Optional) Install Postfix for Sending Notification E-mails

1
sudo apt install -y postfix

Install GitLab CE

1
2
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo EXTERNAL_URL="http://localhost/gitlab" apt-get install gitlab-ce

Note that the certificate is required if you prefer https.

  • [Issue] In case if you run into an issue and get stuck like blow:

    1
    2
    3
    4
    ...
    ...
    ...
    * ruby_block[wait for redis service socket] action run

    To solve the problem, open a new terminal and issue the following command:

    1
    /opt/gitlab/embedded/bin/runsvdir-start

Passenger

By default, GitLab uses NGINX as web server and Unicorn as Rack HTTP server to serve Ruby web applications. Since we want all services, GitLab, Redmine, and MediaWiki, running on Apache web server instead, we therefore disable NGINX and Unicorn, and enable Passenger (Phusion Passenger) as our application server.

Passenger is perfectly integrated with Apache as an Apache module, and you can configure it by Apache configuration file.

Build Passenger Apache module:

1
2
3
sudo apt install -y apache2-dev libapr1-dev libaprutil1-dev
gem install passenger
passenger-install-apache2-module

It will take a while to compile the source. After it’s done, follow the instructions provided on the screen to configure Passenger module correctly for Apache.

Following is an example of my Apache configuration for Passenger.

/etc/apache2/mods-available/passenger.load
1
LoadModule passenger_module /home/jocodoma/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/passenger-6.0.4/buildout/apache2/mod_passenger.so
/etc/apache2/mods-available/passenger.conf
1
2
3
4
<IfModule mod_passenger.c>
PassengerRoot /home/jocodoma/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/passenger-6.0.4
PassengerDefaultRuby /home/jocodoma/.rbenv/versions/2.4.9/bin/ruby
</IfModule>

Enable Passenger module and then restart the Apache service:

1
2
sudo a2enmod passenger
sudo service apache2 restart

Configuration Options

GitLab is configured by setting the relevant options in /etc/gitlab/gitlab.rb. See package defaults for a list of default settings and visit the gitlab.rb.template for a complete list of available options. New installations starting from GitLab 7.6, will have all the options of the template as of installation listed in /etc/gitlab/gitlab.rb by default.

Below are the changes I made:

/etc/gitlab/gitlab.rb
1
2
3
4
5
6
7
external_url 'http://localhost/gitlab'
gitlab_rails['time_zone'] = 'America/Los_Angeles'
gitlab_workhorse['listen_network'] = "tcp"
gitlab_workhorse['listen_addr'] = "127.0.0.1:8181"
web_server['external_users'] = ['www-data']
unicorn['worker_processes'] = 3
nginx['enable'] = false

Reconfigure GitLab:

1
sudo gitlab-ctl reconfigure

References:

Test

In order to run in sub-URI, create a symbolic link for GitLab under /var/www/:

1
sudo ln -s /opt/gitlab/embedded/service/gitlab-rails/ /var/www/gitlab

Let’s move on to the final configuration for sub-URIs on Apache, then we’ll do the tests to verify both Redmine and GitLab.

Apache Configuration for Sub-URIs

Create a folder for gitlab logs:

1
sudo mkdir -p /var/log/apache2/gitlab/

Here’s my Apache sites configuration:

/etc/apache2/sites-available/001-mySites.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
###
### Joseph Chen - 2016.12.28
###

<VirtualHost *:80>
ServerAdmin admin@jocodoma.com
ServerName localhost
ErrorLog /var/log/apache2/mySites_error_log

### Sub URI for Redmine ###
Alias /redmine /var/www/redmine/public
<Location /redmine>
# same as RailsEnv
PassengerAppEnv production

# same as RailsBaseURI
PassengerBaseURI /redmine
PassengerAppRoot /var/www/redmine

# PassengerDefaultUser xxx
PassengerUser jocodoma
</Location>
<Directory "/var/www/redmine/public">
AllowOverride all
Options -MultiViews
#Options Indexes ExecCGI FollowSymLinks
#Order allow,deny
#Allow from all
</Directory>
### --- End Redmine --- ###

### --- GitLab --- ###
ServerSignature Off
ProxyPreserveHost On

# Ensure that encoded slashes are not decoded but left in their encoded state.
# http://doc.gitlab.com/ce/api/projects.html#get-single-project
AllowEncodedSlashes NoDecode

<Location /gitlab>
# New authorization commands for apache 2.4 and up
# http://httpd.apache.org/docs/2.4/upgrading.html#access
Require all granted

ProxyPassReverse http://127.0.0.1:8181
ProxyPassReverse http://localhost/gitlab//

RewriteEngine on
#RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]
</Location>

# needed for downloading attachments
DocumentRoot /var/www/gitlab/public
#Alias /gitlab /var/www/gitlab/public

#Set up apache error documents, if back end goes down (i.e. 503 error) then a maintenance/deploy page is thrown up.
ErrorDocument 404 /404.html
ErrorDocument 422 /422.html
ErrorDocument 500 /500.html
ErrorDocument 502 /502.html
ErrorDocument 503 /503.html

# It is assumed that the log directory is in /var/log/httpd.
# For Debian distributions you might want to change this to
# /var/log/apache2.
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
ErrorLog /var/log/apache2/gitlab/error.log
CustomLog /var/log/apache2/gitlab/forwarded.log common_forwarded
CustomLog /var/log/apache2/gitlab/access.log combined env=!dontlog
CustomLog /var/log/apache2/gitlab/log combined
### --- End GitLab --- ###

### Main Page ###
DocumentRoot /var/www/html
#Alias / /var/www/html
</VirtualHost>

Create a symbolic link to enable the configuration.

1
2
cd /etc/apache2/sites-enabled/
sudo ln -s ../sites-available/001-mySites.conf .
  • Remember to remove the default configuration file, 000-default.conf.

Restart the Apache service:

1
sudo service apache2 restart

Restart GitLab:

1
sudo gitlab-ctl restart

Test

Check following URLs on your browser:
http://localhost/gitLab
http://localhost/redmine
http://localhost/mediawiki

Congratulations! We made it!

(Optional) DirectoryIndex

In case if you want to change the order of index files:

1
sudo pico /etc/apache2/mods-available/dir.conf

Update Services

Redmine

  • Download the latest version of 3.3.x from: http://www.redmine.org/releases/

  • Update

    1
    2
    3
    4
    5
    6
    7
    8
    cd /opt/redmine-3.3.x/
    # RAILS_ENV=production bundle install --without development test
    RAILS_ENV=production bundle _1.17.3_ install --without development test
    RAILS_ENV=production bundle exec rake generate_secret_token
    RAILS_ENV=production bundle exec rake db:migrate
    RAILS_ENV=production bundle exec rake redmine:plugins:migrate
    RAILS_ENV=production bundle exec rake tmp:cache:clear tmp:sessions:clear
    sudo service apache2 restart
  • Remove plugin

    1
    RAILS_ENV=production bundle exec rake redmine:plugins:migrate NAME={plugin} VERSION=0
  • Reset database
    Note that ALL OF YOUR DATA IN DATABASE WILL BE GONE.

    1
    RAILS_ENV=production bundle exec rake db:migrate:reset

Backup Services

Redmine

  • Redmine Database

    1
    2
    export MYPATH=$PWD
    mysqldump -h localhost -u root --password=redminePassword redmineDB | gzip > ${MYPATH}/backup_redmine_DB_`date +20%y_%m_%d`.gz
  • Redmine Files

    1
    2
    export MYPATH=$PWD
    cd /opt/redmine-3.3.9/ && tar zcf ${MYPATH}/backup_redmine_files_`date +20%y_%m_%d`.tgz .

MediaWiki

  • MediaWiki Database

    1
    2
    export MYPATH=$PWD
    mysqldump -h localhost -u root --password=wikiPassword wikiDB | gzip > ${MYPATH}/backup_wiki_DB_`date +20%y_%m_%d`.gz
  • MediaWiki Files

    1
    2
    export MYPATH=$PWD
    cd /opt/mediawiki-1.32.2/ && tar zcf ${MYPATH}/backup_wiki_files_`date +20%y_%m_%d`.tgz .

Restore Databases from Backup

Before you follow the steps to restore database from backup, make sure that the corresponding database is created. Please refer to Install Redmine, or Install MediaWiki.

Reference:
https://www.redmine.org/projects/redmine/wiki/RedmineBackupRestore

Redmine

1
2
# gunzip -c backup_redmine_DB.gz | mysql -u root -p redmineDB  ## for old version
gunzip -c backup_redmine_DB.gz | sudo mysql redmineDB

MediaWiki

1
2
# gunzip -c backup_wiki_DB.gz | mysql -u root -p wikiDB  ## for old version
gunzip -c backup_wiki_DB.gz | sudo mysql wikiDB

Run on Chromebook (crouton)

  • Install iptables package

    1
    2
    sudo apt update
    sudo apt install -y iptables
  • Below is the script to run all services

    /etc/rc.local
    1
    2
    3
    4
    5
    6
    7
    #!/bin/sh
    sudo /opt/gitlab/embedded/bin/runsvdir-start &
    sudo service mysql restart
    sudo service apache2 restart
    sudo /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT ## Accept TCP port 22 for SSH
    sudo /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT ## Accept TCP port 80 for HTTP
    sudo /sbin/iptables -P INPUT DROP ## Block all other inputs