Установка связки Redmine и Nginx

Материал из Записки на полях
Перейти к навигации Перейти к поиску

Step 1 - Install Dependencies

Redmine has a lot of dependencies but we can install them easily with apt. The first step is to become the root user and then update your Ubuntu repository. All further steps in this tutorial get executed as root user, that's why I use "sudo su" instead of prepending sudo to each command.

sudo -i
apt-get update
apt-get upgrade

Install the dependencies of Redmine with the apt command below:

apt-get install mariadb-server mariadb-client libmysqlclient-dev imagemagick libmagickwand-dev libcurl4-openssl-dev git-core subversion

Step 2 - Install Ruby and RVM

In this step, we will install the latest RVM version and Ruby 2.2. Redmine 3.2 stable supports Ruby version 2.2, so we can use it here. RMV (Ruby Version Manager) is a handy command line tool that allows you to install, manage and work with multiple Ruby environments.

gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
curl -L https://get.rvm.io | bash -s stable --ruby

Now we have to reload RVM and add it to .bashrc for automatic reloading:

source /usr/local/rvm/scripts/rvm
echo '[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm"' >> ~/.bashrc


Step 3 - Configure the MySQL Database for Redmine

Выполняем hardening-процедуру, отключая тестовые базы и прочие потенциальные дыры в защите:

mysql_secure_installation

We will create a database and database user for the Redmine installation. Log in to the MySQL shell with the root user and your password:

mysql -u root -p
TYPE YOUR PASSWORD

Next, create a new database called "redmine" and a new user with the name 'redmine' with password 'redmine' (use a better password on your install, this one is just an example), and then grant the privilages for the user 'redmine' to the 'redmine' database.

create database redmine character set utf8;
create user redmine@localhost identified by 'redmine';
grant all privileges on redmine.* to 'redmine'@'localhost';
flush privileges;
exit

The database and user are created. Please use a secure password on your server!

Step 4 - Install Phusion Passenger and Nginx

Phusion Passenger is a web- and app server that can be integrated with Apache and Nginx web servers. It supports multiple languages like Ruby, Python, and Nodejs. It's easy to use, fast and improves the security of the setup. In this part, we will install Phusion Passenger and integrate it with Nginx. Redmine will run under the Nginx web server. Install Passenger with the gem command and then install the passenger-nginx-module.

gem install passenger --no-ri --no-rdoc
passenger-install-nginx-module

The command will ask you about the language that shall be supported, select Ruby and Python here. You will be asked about the Nginx installation, select "Yes: download, compile and install Nginx for me. (recommended)". Finally, you will be asked about the Nginx installation directory, use the default '/opt/nginx/' and press "Enter".


Step 5 - Configure Nginx

Go to the installation directory and edit the nginx.conf file with an editor, I'll use the vim editor here.

vim /opt/nginx/conf/nginx.conf

Paste the configuration line below at the file:

include vhost/*.conf;

Save and exit. Next, create a new 'vhost' directory for the virtual host configuration.

mkdir -p /opt/nginx/conf/vhost

Go to the vhost directory and create a redmine virtual host configuration file with vim:

vim /opt/nginx/conf/vhost/redmine.conf

Paste virtualhost configuration below:

server {
        listen       80;
        server_name  www.redmine.me;

        root /var/www/redmine/public;
        passenger_enabled 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;
        }
}

Save and exit. Next, we will configure Nginx to be started with systemd. Go to the systemd directory and create a new service file 'nginx.service'.

vim /lib/systemd/system/nginx.service

Paste Nginx script for systemd below:

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

Save the file and exit. Reload the systemd services and try to start Nginx with systemctl command:

systemctl daemon-reload
systemctl start nginx

If you want to check Nginx, check the open port 80 with netstat:

netstat -plntu | grep nginx

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4871/nginx

Step 6 - Install Redmine

Make new directory for the Redmine installation, I will use the directory '/var/www/' here.

mkdir -p /var/www/

Go to the '/var/www/' directory and download redmine with the svn command:

cd /var/www/
svn co https://svn.redmine.org/redmine/branches/3.3-stable redmine

Enter the redmine directory and copy the configuration file and database configuration file:

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

Then edit the database.yml file with vim:

vim config/database.yml

On the production line, fill in the details for the database, database user and password. Use the database details that you created in chapter 3.

production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine
  password: "redmine"
  encoding: utf8

Save the file and exit the editor. In the redmine directory, create a new directory and change the owner to www-data:

mkdir -p tmp tmp/pdf public/plugin_assets
sudo chown -R nobody:nogroup files log tmp public/plugin_assets
sudo chmod -R 775 files log tmp public/plugin_assets

Then install the bundler and the gem dependencies for Redmine:

gem install bundler
bundle install --without development test

Now generate the secret token and then generate the database:

bundle exec rake generate_secret_token
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake redmine:load_default_data

Restart Nginx and visit the redmine domain with a web browser:

systemctl restart nginx

Visit redmine installation, in my case: www.redmine.me

Login to the admin page: www.redmine.me/login The default user and password is 'admin'.

Create new sample project. Create a new project in Redmine

The installation of Redmine with Nginx and MariaDB has been finished successfully.

[Можно рассмотреть статью]