Project

General

Profile

Install Redmine 34 on RHEL74 » History » Version 24

Gil Cesar Faria, 2018-02-07 21:34

1 1 Christophe de Dinechin
h1. Install Redmine 3.4 on RHEL7.4
2
3
Here is a procedure that worked for me to install Redmine 3.5 on RHEL 7.4. These instructions work as for Feb 1st, 2018.
4
I also chose to install with Postgres 10 to migrate an existing instance, although I believe it works with the default Postgres 9.2.
5
6
h2. Dependencies
7
8
Install the required packages.
9
<pre>
10 22 Gil Cesar Faria
% sudo yum -y install zlib-devel curl-devel openssl-devel httpd-devel apr-devel apr-util-devel mysql-devel postgresql-devel ImageMagick-devel libffi-devel
11 1 Christophe de Dinechin
</pre>
12
13 24 Gil Cesar Faria
If you plan to use Postgres 10, install the following required packages:
14 23 Gil Cesar Faria
<pre>
15
% sudo yum -y install libpqxx libpqxx-devel postgresql10.x86_64 postgresql10-server postgresql10-contrib postgresql10-libs postgresql10-tcl
16
</pre>
17
18 1 Christophe de Dinechin
h2. Choice of database
19
20
Install your database of choice. I've mostly tested with Postgres 10.
21
22 2 Christophe de Dinechin
h3. Postgres 10
23 1 Christophe de Dinechin
24 2 Christophe de Dinechin
You can upgrade to Postgres 10 if you need for example to transfer an existing database.
25 1 Christophe de Dinechin
<pre>
26 2 Christophe de Dinechin
# More recent Postgres 10
27
% sudo yum -y install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-1.noarch.rpm
28 3 Christophe de Dinechin
% sudo yum install -y postgresql10-server postgresql10 postgres-devel
29 4 Christophe de Dinechin
% export PATH=/usr/pgsql-10/bin/:$PATH
30 5 Christophe de Dinechin
% postgresql-10-setup initdb
31 1 Christophe de Dinechin
</pre>
32
33 2 Christophe de Dinechin
Note that the @postgres-devel@ package is still required for the @bundle install@ step below, and I am not sure if that step works with Postgres 10.
34 1 Christophe de Dinechin
35 2 Christophe de Dinechin
Like for Postgres 9, you need to add @trust@ for local IPv6 connexions in @/var/lib/pgsql/10/data/pg_hba.conf@:
36 1 Christophe de Dinechin
37
<pre>
38
# TYPE  DATABASE        USER            ADDRESS                 METHOD
39
40
# "local" is for Unix domain socket connections only
41
local   all             all                                     peer
42
# IPv4 local connections:
43
host    all             all             127.0.0.1/32            trust
44
# IPv6 local connections:
45
host    all             all             ::1/128                 trust
46 16 Christophe de Dinechin
</pre>
47
48
You can then start the database server:
49
<pre>
50
% sudo systemctl start postgresql-10
51
% sudo systemctl enable postgresql-10
52 1 Christophe de Dinechin
</pre>
53
54
Check that you can connect to the database, then create the @redmine@ user and a @redmine@ database:
55
<pre>
56
% sudo su - postgres
57 6 Christophe de Dinechin
% export PATH=/usr/pgsql-10/bin/:$PATH
58 1 Christophe de Dinechin
% psql
59
postgres=# alter role postgres with encrypted password 'insert-your-postgres-password-here';
60
postgres=# create user redmine with encrypted password 'insert-your-redmine-password-here';
61
postgres=# create database redmine with encoding 'UTF-8' owner redmine;
62
</pre>
63
64 7 Christophe de Dinechin
If you get an error related to the encoding (I only had that on Postgres 9):
65 1 Christophe de Dinechin
<pre>
66
ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
67
HINT:  Use the same encoding as in the template database, or use template0 as template.
68
</pre>
69
70
then you should explicitly use @template0@:
71
<pre>
72
postgres=# create database redmine with template=template0 encoding 'UTF-8' owner redmine;
73 3 Christophe de Dinechin
</pre>
74 1 Christophe de Dinechin
75 2 Christophe de Dinechin
h3. Postgres 9.2.23
76 1 Christophe de Dinechin
77 2 Christophe de Dinechin
Postgres 9.2.23 is what you get directly when installing with @yum@ in RHEL 7.4:
78 1 Christophe de Dinechin
<pre>
79 2 Christophe de Dinechin
# Default Postgres 9.2.23
80
% sudo yum -y install postgresql postgresql-server postgresql-devel
81 1 Christophe de Dinechin
% postgresql-setup initdb
82 2 Christophe de Dinechin
% sudo systemctl start postgresql
83
% sudo systemctl enable postgresql
84 1 Christophe de Dinechin
</pre>
85
86 2 Christophe de Dinechin
I have not been able to have Redmine connect to the database without altering @/var/lib/pgsql/data/pg_hba.conf@ to have @trust@ for local IPv6 connnexions:
87 1 Christophe de Dinechin
88
<pre>
89
# TYPE  DATABASE        USER            ADDRESS                 METHOD
90
91
# "local" is for Unix domain socket connections only
92
local   all             all                                     peer
93
# IPv4 local connections:
94
host    all             all             127.0.0.1/32            trust
95
# IPv6 local connections:
96
host    all             all             ::1/128                 trust
97
</pre>
98
99 2 Christophe de Dinechin
I suspect this is wrong, but I don't know how to do it "right", and that's also how it's configured in the Redmine docker containers I looked at.
100
101 1 Christophe de Dinechin
Create user and database like in the previous section.
102
103 2 Christophe de Dinechin
h3. For MySQL / MariaDB
104
105
Installing and starting the database server
106
<pre>
107
# MariaDB (formerly MySQL)
108
% sudo yum -y install mariadb mariadb-devel
109
% sudo systemctl start mariadb
110
% sudo systemctl enable mariadb
111
</pre>
112
113
Then you can setup the original database:
114
<pre>
115
% mysql -u root -p
116
MariaDB [(none)]> set password for 'root'@'localhost' = password('insert-your-password-here');
117
MariaDB [(none)]> create database redmine character set utf8;
118
MariaDB [(none)]> create user 'redmine'@'localhost' identified by 'somepass';
119
MariaDB [(none)]> grant all privileges on redmine.* to 'redmine'@'localhost';
120
</pre>
121
122
Note: The rest of this setup assumes Postgres, will need to be updated with MariaDB instructions as well.
123 1 Christophe de Dinechin
124
h2. Upgrade Ruby
125
126
The default @ruby@ is 2.0.0p648. If you keep that version, @gem install passenger@ fails.
127
128
<pre>
129 8 Christophe de Dinechin
% sudo yum install -y gcc
130 1 Christophe de Dinechin
% cd /usr/local/src
131
% wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0.tar.gz
132
% tar xvfz ruby-2.5.0.tar.gz
133
% cd ruby-2.5.0/
134
% ./configure
135
% make
136 9 Christophe de Dinechin
% sudo make install
137 1 Christophe de Dinechin
</pre>
138
139
Verify that you have Ruby 2.5 installed after that: 
140
<pre>
141 10 Christophe de Dinechin
% export PATH=/usr/local/bin:$PATH
142 1 Christophe de Dinechin
% ruby -v
143
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]
144
</pre>
145
146
h2. Install passenger and Gem bundler:
147
148
With Ruby 2.5, we can install Passenger:
149
<pre>
150
% gem install passenger
151
gem install passenger
152
Fetching: rack-2.0.3.gem (100%)
153
Successfully installed rack-2.0.3
154
Fetching: passenger-5.2.0.gem (100%)
155
Building native extensions. This could take a while...
156
Successfully installed passenger-5.2.0
157
Parsing documentation for rack-2.0.3
158
Installing ri documentation for rack-2.0.3
159
Parsing documentation for passenger-5.2.0
160
Installing ri documentation for passenger-5.2.0
161
Done installing documentation for rack, passenger after 53 seconds
162
2 gems installed
163
</pre>
164
165
Install Gem bundler:
166
<pre>
167
% gem install bundler
168
Fetching: bundler-1.16.1.gem (100%)
169
Successfully installed bundler-1.16.1
170
Parsing documentation for bundler-1.16.1
171
Installing ri documentation for bundler-1.16.1
172
Done installing documentation for bundler after 5 seconds
173
1 gem installed
174
</pre>
175
176
h2. Check out Redmine
177
178 11 Christophe de Dinechin
Add a @redmine@ user
179 1 Christophe de Dinechin
180
<pre>
181 11 Christophe de Dinechin
% sudo useradd redmine
182 1 Christophe de Dinechin
</pre>
183
184 12 Christophe de Dinechin
Install @svn@ to be able to checkout Redmine:
185
<pre>
186
% sudo yum -y install svn
187
</pre>
188
189 11 Christophe de Dinechin
Check out the version of Redmine you want, here with version 3.4:
190
<pre>
191
% su redmine
192 1 Christophe de Dinechin
% cd /var/www
193 11 Christophe de Dinechin
% svn co http://svn.redmine.org/redmine/branches/3.4-stable redmine
194 1 Christophe de Dinechin
</pre>
195
196
h2. Database configuration
197
198
The database configuration for Redmine is in @/var/www/redmine/config/database.yml@. There is a template in that directory which you can edit.
199
200
<pre>
201
% cd /var/www/redmine/config/
202
% cp database.yml.example database.yml
203
</pre>
204
205
Edit @database.yml@ to contain the correct information regarding your installation. For Postgres:
206
207
<pre>
208
production:
209
  adapter: postgresql
210
  database: redmine
211
  host: localhost
212
  username: redmine
213
  password: insert-your-password-here
214
</pre>
215
216
(Note that you always have the choice of running the database in some other host than @localhost@)
217
218
h2. Install dependencies using the Gem bundler
219
220
This step will look at the dependencies specified in the @Gemfile@:
221
222
<pre>
223 13 Christophe de Dinechin
% cd /var/www/redmine
224 1 Christophe de Dinechin
% bundle install
225
</pre>
226
227
You may have a message about YARD recommending you use the following command:
228
<pre>
229
% yard config --gem-install-yri
230
Updated ~/.gemrc: 'gem: --document=yri'
231
</pre>
232
233
h2. Setup the production environment 
234
235
Update @/var/www/redmine/config/environment.rb@, adding the following statement:
236
<pre>
237
ENV['RAILS_ENV'] ||= 'production'
238
</pre>
239
240
Generate a secret token:
241
<pre>
242
% RAILS_ENV=production bundle exec rake generate_secret_token
243
</pre>
244
245
Run the database migration step:
246
<pre>
247
% RAILS_ENV=production bundle exec rake db:migrate
248
</pre>
249
250
h2. Start the server
251
252 17 Christophe de Dinechin
Note that you may want to open the firewall for that port using @firewall-config@ or @firewall-cmd@, e.g.
253
<pre>
254
% sudo firewall-cmd  --zone=public --add-port=3000/tcp --permanent
255
</pre>
256
257 1 Christophe de Dinechin
You can now attempt to run the application:
258
<pre>
259
% sudo su - redmine
260
% cd /var/www/redmine
261
% /usr/local/bin/ruby bin/rails server -b 0.0.0.0 -e production
262
=> Booting WEBrick
263
=> Rails 4.2.8 application starting in production on http://0.0.0.0:3000
264
=> Run `rails server -h` for more startup options
265
=> Ctrl-C to shutdown server
266
[2018-02-01 12:49:02] INFO  WEBrick 1.4.2
267
[2018-02-01 12:49:02] INFO  ruby 2.5.0 (2017-12-25) [x86_64-linux]
268
[2018-02-01 12:49:02] INFO  WEBrick::HTTPServer#start: pid=21470 port=3000
269
</pre>
270 18 Christophe de Dinechin
271
272
h2. Optional installations
273
274
If you are using a revision control system, you may want something like (pick which ones apply):
275
<pre>
276
% yum -y install darcs hg cvs bzr git
277
</pre>
278 19 Christophe de Dinechin
279
h2. Add a systemd service
280
281
You can optionally ensure your server starts automatically by creating a systemd service for it in @ /usr/lib/systemd/system/redmine.service@.
282
283
<pre>
284
[Unit]
285
Description=Redmine server
286
After=network.target remote-fs.target nss-lookup.target
287
288
[Service]
289
Type=simple
290
User=redmine
291
Group=redmine
292
EnvironmentFile=/etc/sysconfig/httpd
293
ExecStart=/usr/local/bin/ruby /var/www/redmine/bin/rails server -b 0.0.0.0 -e production
294
TimeoutSec=300
295
ExecStop=/bin/kill -WINCH ${MAINPID}
296
297
[Install]
298
WantedBy=multi-user.target
299
</pre>
300 20 Christophe de Dinechin
301
h2. Adding https support
302
303 21 Christophe de Dinechin
h3. Create Apache virtual host
304
305 20 Christophe de Dinechin
This is assuming you want to connect directly using the server name. Create a file named for example @/etc/httpd/conf.d/redmine.conf@, containing:
306
307
<pre>
308
<VirtualHost *:443>
309
  ServerName my-server-name@my-domain.com
310
  ServerAdmin my-admin-name@my-domain.com
311
  ErrorLog "logs/redmine_error_log"
312
313
  SSLEngine on
314
  SSLCertificateFile /etc/pki/tls/certs/ca.crt
315
  SSLCertificateKeyFile /etc/pki/tls/private/ca.key
316
317
  DocumentRoot /var/www/redmine/public
318
319
  <Directory /var/www/redmine/public>
320
    AllowOverride all
321
    Options -MultiViews
322
  </Directory>
323
324
</VirtualHost>
325
</pre>
326
327 21 Christophe de Dinechin
h3. Create .htaccess with rewrite rules to dispatch.cgi
328
329 20 Christophe de Dinechin
Note that you need to have created the certificates (plenty of resources on the web on how to do that)
330
331
Add the following in @/var/www/redmine/public/.htaccess@:
332
333
<pre>
334
# General Apache options
335
<IfModule cgi_module>
336
    AddHandler cgi-script .cgi
337
</IfModule>
338
<IfModule mod_fastcgi.c>
339
    AddHandler fastcgi-script .fcgi
340
</IfModule>
341
<IfModule mod_fcgid.c>
342
    AddHandler fcgid-script .fcgi
343
</IfModule>
344
Options +FollowSymLinks +ExecCGI
345
346
# If you don't want Rails to look in certain directories,
347
# use the following rewrite rules so that Apache won't rewrite certain requests
348
#
349
# Example:
350
#   RewriteCond %{REQUEST_URI} ^/notrails.*
351
#   RewriteRule .* - [L]
352
353
# Redirect all requests not available on the filesystem to Rails
354
# By default the cgi dispatcher is used which is very slow
355
#
356
# For better performance replace the dispatcher with the fastcgi one
357
#
358
# Example:
359
#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
360
RewriteEngine On
361
362
# If your Rails application is accessed via an Alias directive,
363
# then you MUST also set the RewriteBase in this htaccess file.
364
#
365
# Example:
366
#   Alias /myrailsapp /path/to/myrailsapp/public
367
#   RewriteBase /myrailsapp
368
369
RewriteRule ^$ index.html [QSA]
370
RewriteRule ^([^.]+)$ $1.html [QSA]
371
RewriteCond %{REQUEST_FILENAME} !-f
372
<IfModule cgi_module>
373
    RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
374
</IfModule>
375
<IfModule mod_fastcgi.c>
376
    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
377
</IfModule>
378
<IfModule mod_fcgid.c>
379
    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
380
</IfModule>
381
382
# In case Rails experiences terminal errors
383
# Instead of displaying this message you can supply a file here which will be rendered instead
384
#
385
# Example:
386
ErrorDocument 500 /500.html
387
</pre>
388
389 21 Christophe de Dinechin
h3. Create the dispatch.cgi file
390
391 20 Christophe de Dinechin
Finally, you need a @/var/www/redmine/public/dispatch.cgi@ script:
392
<pre>
393
#!/usr/local/bin/ruby                                                                                                                                                                                          
394
395
require File.dirname(__FILE__) + '/../config/boot'
396
require File.dirname(__FILE__) + '/../config/environment'
397
398
class Rack::PathInfoRewriter
399
  def initialize(app)
400
    @app = app
401
  end
402
403
  def call(env)
404
    env.delete('SCRIPT_NAME')
405
    parts = env['REQUEST_URI'].split('?')
406
    env['PATH_INFO'] = parts[0]
407
    env['QUERY_STRING'] = parts[1].to_s
408
    @app.call(env)
409
  end
410
end
411
412
Rack::Handler::CGI.run Rack::PathInfoRewriter.new(RedmineApp::Application)
413
</pre>
414 21 Christophe de Dinechin
415
h3. Adjusting the SELinux policy
416 20 Christophe de Dinechin
417
You also need to make sure that Apache is allowed to execute all that part:
418
419
<pre>
420
% cd /var/www/redmine/public
421
% sudo chown -R apache:apache .
422
% sudo chmod +x dispatch.cgi
423
</pre>
424
425
Finally, it's necessary to create an SELinux policy allowing that CGI script to run, otherwise you will get an internal server error:
426
427
<pre>
428
% sudo semanage boolean -m --on httpd_enable_cgi
429
% sudo semanage fcontext -a -t httpd_sys_script_exec_t /var/www/redmine/public
430
% sudo restorecon /var/www/redmine/public
431
% sudo setsebool -P httpd_can_network_connect 1
432
% sudo setsebool -P httpd_can_network_connect_db 1
433
% ausearch -c 'dispatch.cgi' --raw | audit2allow -M my-dispatchcgi
434
% semodule -i my-dispatchcgi.pp
435
</pre>