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