Skip to content

Instantly share code, notes, and snippets.

@mactree
Forked from quazgar/OpenProjectInstallation.md
Last active August 23, 2017 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mactree/3f6bd1af044c46721d7464f238cb01d8 to your computer and use it in GitHub Desktop.
Save mactree/3f6bd1af044c46721d7464f238cb01d8 to your computer and use it in GitHub Desktop.
Install OpenProject (latest) with Memcached on Uberspace

Install OpenProject (latest) with Memcached on Uberspace

Thanks to @tessi and @jesk and @biolauri for their gists:

Some advantages to these gists:

  • Use Memcached as cache server
  • Works with latest version of OpenProject (7.0 and newer)
  • Removed unnecessary instructions

Prerequisites

daemontools

If not already done, we initialize the daemontools first:

test -d ~/service || uberspace-setup-svscan

node.js

The latest versions of node.js are already preinstalled on theserver. You just have to add it to your $PATH. We use version 6, as it's the latest LTS release.

cat <<__EOF__ >> ~/.bash_profile
export PATH=/package/host/localhost/nodejs-6/bin:\$PATH
__EOF__

source ~/.bash_profile

npm

We use npm (and have to update it with the global option), so we need to give it a config to not make our home directory visible to other users on the server:

cat > ~/.npmrc <<__EOF__
prefix = $HOME
umask = 077
__EOF__

Updating to the latest version

The current version of npm distributed on Uberspaces is a bit old and has a fatal bug, so we need to install our own:

npm install npm@latest -g

Tell the shell to use our installed version instead of the one from Uberspace. We have to do this, because the first occurence within $PATH locations is used, so we need to add our own installation at the beginning:

cat <<__EOF__ >> ~/.bash_profile
# Reread home directory for newer version of npm
export PATH=\$HOME/bin:\$PATH
__EOF__

Installing Memcached

Uberspace is a shared hosting service, so a global Memcached is a security risk. We need to install our own memcached (thanks to Florian Schmidt instructions; updated according to some instructions from Uberspace via Twitter:

toast arm https://memcached.org/files/memcached-1.4.33.tar.gz

Memcached daemon

And to manage it with the daemontools, we have to set up its run file:

mkdir ~/etc/memcached
mkdir ~/etc/memcached/run-memcached
cd ~/etc/memcached/run-memcached/

cat <<__EOF__ > run
#!/bin/sh
exec memcached -s $HOME/memcached.socket 2>&1
__EOF__

chmod +x run
cd ~

And the logging daemon:

mkdir ~/etc/memcached/run-memcached/log
cd ~/etc/memcached/run-memcached/log/

cat <<__EOF__ > run
#!/bin/sh
exec multilog t ./main
__EOF__

chmod +x run
cd ~

Finally, we link the run script to start the daemon:

ln -s ~/etc/memcached/run-memcached ~/service/run-memcached

OpenProject

Installation

Please read the official installation instructions first!

I prefer to install OpenProject within ~/ror/openproject, but you may change this to any directory within your user directory (but not within /var/www/virtual/!).

mkdir -p ~/ror/openproject
cd ~/ror/openproject

Clone the OpenProject Community Edition git repository from GitHub (branch stable/7 is the current release branch with version 6 and so on):

git clone https://github.com/opf/openproject-ce.git --branch stable/7 --depth 1
cd openproject-ce/

Install OpenProject with all dependencies:

RAILS_ENV=production bundle install --without postgres sqlite development test therubyracer docker
npm install

Configuration

Copy the example configuration files (you have to edit them both after this step):

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

config/database.yml

In the database configuration file, you have to add your username, password (get it from your .my.cnf). Your database has to be prefixed with your username, following an underscore. For example (change %username with your username and %password with your password):

production:
  adapter: mysql2
  database: %username_openproject
  host: localhost
  username: %username
  password: %password
  encoding: utf8

You should do this for all environments (production, development, test).

config/configuration.yml

The email_delivery_method is :sendmail, rails_cache_store :memcache and you have the cache_memcache_server should point to your memcached.socket file used in the Memcached installation (e.g. "/home/%username/memcached.socket"). All entries beginning with smtp_ should be commented out.

A minimal configuration file looks like (you can use this instead of copying the example file):

default: 
  email_delivery_method: :sendmail
  rails_cache_store: :memcache
  cache_memcache_server: "/home/%username/memcached.socket"

config/environments/production.rb

You have to tell ruby to serve the static files itself: Change config.public_file_server.enabled = false to true!

Database initialization

Run last installation steps and seed sample data:

RAILS_ENV=production bundle exec rake db:create
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production LOCALE=de bundle exec rake db:seed

With the last command (db:seed), you get a demo project and some useful status strings. With LOCALE, you can change the language of these (e.g. LOCALE=fr for French or without for english). Just ignore this step and you have no sample data.

OpenProject daemons

First of all, choose a port between 61000 and 65535 (OpenProject uses its own server, so we have to redirect the traffic to this port) and then test if it's not already in use (the command returns nothing, if it's free):

netstat -tulpen | grep %port

Change %port with your selected port number.

Add the run script for your daemons (change %username with your username!):

mkdir ~/etc/openproject
mkdir ~/etc/openproject/run-openproject-web
cd ~/etc/openproject/run-openproject-web/

cat << __EOF__ > run
#!/bin/sh

# These environment variables are sometimes needed by the running daemons
export USER=%username
export HOME=/home/%username

# Include the user-specific profile
. \$HOME/.bash_profile

# Now let's go!
export RAILS_ENV="production"
export OPENPROJECT_PATH="\$HOME/ror/openproject/openproject-ce"

cd \$OPENPROJECT_PATH/

__EOF__

chmod +x run

And, once again, the logging:

mkdir log

cat <<__EOF__ > log/run
#!/bin/sh
exec multilog t ./main
__EOF__

chmod +x log/run

Copy all files for the worker daemon:

cd ..
cp -r run-openproject-web/ run-openproject-worker/

Add the actual commands to both run scripts: Change %port with your selected port number.

cat <<__EOF__ >> run-openproject-web/run
# Generate secret key for cookies
export SECRET_KEY_BASE=\$(rake secret)

exec bundle exec unicorn --port %port --env production 2>&1
__EOF__

cat <<__EOF__ >> run-openproject-worker/run
exec bundle exec rake jobs:work 2>&1
__EOF__

Link the run scripts to start the daemons (and OpenProject):

ln -s ~/etc/openproject/run-openproject-web ~/service/run-openproject-web
ln -s ~/etc/openproject/run-openproject-worker ~/service/run-openproject-worker

Redirection of all traffic to OpenProject

Add an .htaccess file to your document root for a RewriteRule with Proxy. Change the directory, if you want to access it within a subdirectory. Change %port with your selected port number.

cd ~/html

cat <<__EOF__ >> .htaccess
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{ENV:HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteRule (.*) http://localhost:%port/\$1 [P]
__EOF__

You did it!

Just open the url of your uberspace (e.g. username.server.uberspace.de) or domain, where you added your redirect .htaccess and immediately change your admin password! Your current username and password is admin.

Now, you have to configure your installation to fit your needs. Some things you may change in the system configuration:

  • General
  • Hostname (the example may work)
  • Protocol (you should set it to HTTPS)
  • Authentication
  • login required (check for private installations)
  • self registration (deactivate for private installations)
  • Notifications
  • mail from

Please be aware that if you set/change a password for a user within the admin panel, it will be sent in clear text via email!

Logging

You can use zcat -f ~/service/run-openproject-web/log/main/* | tai64nlocal | less to see the logging of the OpenProject web service. With svc -du ~/service/run-openproject-web, you can start and stop the service immidiately to reload configuration.

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