Skip to content

Instantly share code, notes, and snippets.

@gruentee
Forked from mamiu/install_habitrpg.md
Last active March 5, 2017 09:55
Show Gist options
  • Save gruentee/e819de34cdf4ebe4487a8c052e7d11fb to your computer and use it in GitHub Desktop.
Save gruentee/e819de34cdf4ebe4487a8c052e7d11fb to your computer and use it in GitHub Desktop.
Install HabitRPG on Uberspace.

##This is a guide to install HabitRPG on an Uberspace.

###Prerequisites Be sure to have NodeJS >= 6 and NPM >= 3.10.10 installed. The latter is neccessary for BCrypt (dependency) to build properly. Instructions on how to set NodeJS versions can be found in the article on NodeJS in the uberspace wiki.

You may install custom Node/NPM versions on your uberspace using Node Version Manager (https://github.com/creationix/nvm).

Once the correct Node and NPM verions are installed, make sure a recent Compiler version is used to build BCrypt:

export PATH=/package/host/localhost/gcc-4/bin:$PATH

###Installation

First you have to create a folder which is accessable from the web (e.g. habitrpg.yourdomain.com) and then move to it. In this folder execute

git clone https://github.com/HabitRPG/habitrpg.git .

After that, you have to download some dependencies with:

npm install -g gulp grunt-cli bower mocha
npm install

Now you have all necessary files on your server.

###Configuration

To configure HabitRPG for uberspace you have to copy the config.json.example to config.json with

cp config.json.example config.json

Now look for a free port between 61000 and 65536. (Node apps need a specific port, where they can listen). To check which ports are used you can issue this command:

netstat -tulpen | column -t | grep ':6[1-5][0-9]\{3\}'

####Production mode Be sure to also set NODE_ENV to production to run Habitica in production mode. Assets (images, CSS, JS) will be minified and compressed for faster delivery. I figured it's neccessary to run gulp build:prod once before running Habitica so this processes gets taken care of.

Of course we need to redirect the traffic from your domain to the port your app will be running on. Moreover you need to set some HTTP headers to tell Habitica requests are being proxied by Apache. Otherwise it will redirect you to the URL BASE_URL is set to. So create a file called .htaccess and put the following in it (remember to correct the port to the one, you've chosen):

RewriteEngine On
Header set x-habitica-lb "Yes"
RequestHeader set x-habitica-lb "Yes"
RewriteRule ^(.*) http://localhost:<YOUR_PORT>/$1 [P]

We also need a database. HabitRPG uses mongodb, so we have to set up a mongodb instance. On an Uberspace that's a no-brainer. ;) Just hit

uberspace-setup-mongodb

Keep the data wherever you want, but keep it. (You can check the mongo instance with mongo admin --port <YOUR_MONGO_PORT> -u '<YOUR_MONGO_USERNAME>' -p '<YOUR_MONGO_PASSWORD>' [replace the <YOUR_MONGO_*>-tags with the output from uberspace-setup-mongodb]. Ctrl-C to exit.)

Ok, lets open the config.json file and edit following lines:

  • The PORT to the port you've chosen
  • The NODE_DB_URI to "mongodb://<YOUR_MONGO_USERNAME>:<YOUR_MONGO_PASSWORD>@localhost:<YOUR_MONGO_PORT>/db?authSource=admin" (replace the <YOUR_MONGO_*>-tags with the data from uberspace-setup-mongodb.
  • The SESSION_SECRET to a random key with 50 characters (alphanumeric)

If you want, you can change the remaining configurations later, but for now it's enough to get HabitRPG running.

###Bring it to life

npm start

Once you're sure your Habitica is running smoothly, you can set up a daemontools service so that Habitica runs continuously and is restarted in case of a crash or server reboot. Instructions are found in the following articles on uberspace wiki (German):

######Have fun!

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