How to install Sharetribe for Ubuntu 16.04

Sharetribe is a popular opensource marketplace, written in Ruby. Although it is a very professional platform and with a great user experience, the installation is quite complex. Here is probably the best tutorial to install Sharetribe on Ubuntu.

 

Update (27-nov-2017): As I am receiving a lot of emails to support people on this application, I have enriched my tutorial to cover the systemd scripts, virtualhost and email SMTP configurations.

Update (7-Jan-2018): Added a Stripe configuration section

Enjoy!

 

Installation

Assuming you start from a fresh Ubuntu 16.04 Server version, here is the full doc:

1) Install git  and clone their repository

You can do it in the folder of your choice.

sudo apt-get install git-core
git clone git://github.com/sharetribe/sharetribe.git
cd sharetribe
git checkout latest

This will download around 110mb, so stay tuned.

 

2) Install few requirements

Before to install Ruby, we will need to install curl, you will also need imagemagick and NodeJS for Sharetribe.

They are using the Node.js 7.8. Using the default one in the repo will not work then. Here is what you need to run:

sudo apt-get install build-essential libssl-dev curl imagemagick -y
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh -o install_nvm.sh
bash install_nvm.sh
source ~/.profile

Then list the available version and install the 7.8

nvm ls-remote
nvm install 7.8.0
nvm use 7.8.0
3) Create the needed MySQL Database and configure the file named database.yml

If you do not have a MySQL database ready, you could follow this tutorial, or simply run:

sudo apt-get install mysql-server -y

It will ask you to set up a root password.

 

You can either use PHPMyAdmin or simply do it in command line:

mysql -u root -p

it will prompt for your MySQL root password.

When you are connected to your MySQL server, you will need to create 1 database and 1 user associated to this database.

  • Database:

    CREATE DATABASE sharetribe_production CHARACTER SET utf8 COLLATE utf8_general_ci;

  • User

Change PASSWORD by a strong password you want to create.

GRANT all privileges ON sharetribe_production.* TO 'sharetribe'@'localhost' IDENTIFIED BY 'PASSWORD';
  • And then simply exit

    exit

  • Now create a database.yml file by copying the example database configuration:

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

and configure the “production” part of it with your favorite text editor. (You will only need to add the user/password for the user you have just created)

nano config/database.yml

 

4) Install Sphinx

Sphinx is a requirement of Sharetribe. I suggest you to use the latest one available on their official website.

The latest version at the time of this article is the 2.2.11. Hence I have downloaded their .deb version in AMD64 (64bits) for Ubuntu and installed it. But first, you will need some dependencies as well, or else, the installation of Sphinx will fail.

sudo apt-get install libmysqlclient20 libodbc1 libpq5 -y
wget http://sphinxsearch.com/files/sphinxsearch_2.2.11-release-1~xenial_amd64.deb
sudo dpkg -i sphinxsearch_2.2.11-release-1~xenial_amd64.deb
5) Install Ruby

You will need to use the  version 2.3.4 based on their documentation (This version, may change, I suggest you to check their requirements page first.)

To ease our job, we will use RVM

  • First, import the GPG key (under your regular user)

    gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

  • Then, install the latest version of RVM

    curl -sSL https://get.rvm.io | bash -s stable

  • Now install Ruby 2.3.4

    source ~/.rvm/scripts/rvm rvm install 2.3.4

This will download and compile ruby-2.3.4 for your system. It may takes some time depending on your bandwidth and computer speed

  • Install the rubygems by running:

    rvm rubygems current

  • And ensure you are using the Ruby version 2.3.4 (needed if you have different Ruby versions installed on your server)

    rvm use 2.3.4

6) Install the required gems
  • First you will need couples of dependencies

– LibXML2 and XSLT to avoid a failure with the gem nokogiri

sudo apt-get install libxslt-dev libxml2-dev -y

-LibMYSQLclient to avoid a failure with mysql2

sudo apt-get install libmysqlclient-dev -y
  • Install the gem “bundler” and “mailcatcher”

    gem install bundler gem install mailcatcher

  • Run the installation

    bundle install

You should normally have no error. If you do, it’s probably a lacking dependency. (Please let me know if it is the case)

 

7) Install node modules:
npm install

This will take quite some time (coffee time?) but should be straightforward.

 

7) Set-up Sharetribe for production mode

First you need to configure you secret key

  • Generate a key

    rake secret

and copy the key.

  • Create or modify the config file to add the key

    nano config/config.yml

and add:

production:
  secret_key_base: # add here the generated key
  • Then prepare the environment

    RAILS_ENV=production bundle exec rake db:create RAILS_ENV=production bundle exec rake db:structure:load RAILS_ENV=production bundle exec rake ts:index RAILS_ENV=production bundle exec rake ts:start RAILS_ENV=production NODE_ENV=production bundle exec rake assets:precompile

If any error happen, you will need to fix them before continuing.

Now invoke the delayed job worker

RAILS_ENV=production bundle exec rake jobs:work

and in a new window, start the server

source ~/.rvm/scripts/rvm
cd sharetribe
bundle exec rails server -e production

You should now have a working Sharetribe server and it should be accessible through the port 3000 of your server.

 

If you wish to use your own domain name, it is now the best time to configure the database accordingly.

You need to change the domain default value in the database. You can either do it in SQL or with phpmyadmin.

sudo apt-get install phpmyadmin

Once installed, you need to modify the value domain (By the domain name without http://) and the value use_domain (By 1), in the table “communities”

8) Set-up Stripe as payment gateway

It seems with the opensource version, it is very difficult to get a merchant account for Paypal, so most of the users are using Stripe itself. Here is how to configure it.

Get a ruby shell:

bundle exec rails c -e production

and run the 2 commands:

TransactionService::API::Api.processes.create(community_id: 1, process: :preauthorize, author_is_seller: true)
TransactionService::API::Api.settings.provision( community_id: 1, payment_gateway: :stripe, payment_process: :preauthorize, active: true)

Now, configure your config.yml

nano config/config.yml

and add:

stripe_private_key_pattern: "sk_(test|live)_.{24}"
stripe_publishable_key_pattern: "pk_(test|live)_.{24}"
app_encryption_key: "2617463e32b65ec6645b3cb661f9686f2ab608c18ac930ee1295a1c1170504ed"

restart the service, or follow the next steps to setup SystemD Startup scripts, and you will have a new Payment setting menu in the admin section. Simply ad your Stripe APIs (Publishable and Secret) to finish the Stripe setup.

 

9) Create SystemD scripts

You have now a working instance of Sharetribe. But it will stop when you close your SSH connection or when you restart your machine. The idea is to have it started as a daemon / at the startup.

I did not find much info on this, so I reuse some pieces there and there. Is it the best way? I don’t know. But it works 😉

Since you are having to command line to run, i made 3 services.

sudo nano /etc/systemd/system/sharetribe.service

and paste:

<pre class="show-plain-default:true lang:default highlight:0 decode:true ">[Service]
WorkingDirectory=/home/ubuntu/sharetribe
ExecStart=/bin/bash -lc 'source /home/ubuntu/.profile && source /home/ubuntu/.rvm/scripts/rvm && bundle exec rake ts:index && bundle exec rake ts:start'
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=sharetri
User=ubuntu
Group=ubuntu
Environment=RAILS_ENV=production

[Install]
WantedBy=multi-user.target

Save the doc and create another one:

sudo nano /etc/systemd/system/sharetribe2.service

and paste:

<pre class="show-plain-default:true lang:default highlight:0 decode:true">[Service]
WorkingDirectory=/home/ubuntu/sharetribe
ExecStart=/bin/bash -lc 'source /home/ubuntu/.profile && source /home/ubuntu/.rvm/scripts/rvm && bundle exec rake jobs:work'
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=sharetri
User=ubuntu
Group=ubuntu
Environment=RAILS_ENV=production NODE_ENV=production

[Install]
WantedBy=multi-user.target

Save the doc and create the third one:

sudo nano /etc/systemd/system/sharetribe3.service

with

<pre class="show-plain-default:true lang:default highlight:0 decode:true">[Service]
WorkingDirectory=/home/ubuntu/sharetribe
ExecStart=/bin/bash -lc 'source /home/ubuntu/.rvm/scripts/rvm && bundle exec rails server -e production'
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=sharetri2
User=ubuntu
Group=ubuntu

[Install]
WantedBy=multi-user.target

Now enable them:

sudo systemctl enable sharetribe
sudo systemctl enable sharetribe2
sudo systemctl enable sharetribe3

then reload the systemd daemon to take into accounts your changes

sudo systemctl daemon-reload

and start them:

sudo systemctl start sharetribe
sudo systemctl start sharetribe2
sudo systemctl start sharetribe3

It should now be running. Have a look to YourIP:3000 to ensure it works.

 

10) Virtualhost configuration

Now that your Sharetribe instance is working, you probably want to give it a friendlier URL, like myshop.com, without the need to enter the port. We will do it with a virtualhost configuration and the proxypass fonction. (of course, I assume you have apache2 installed)

First, create a virtualhost:

sudo nano /etc/apache2/sites-available/sharetribe.conf

and paste

<pre class="show-plain-default:true lang:default highlight:0 decode:true"><VirtualHost *:80>
ServerAdmin contact@myshop.com
ServerName myshop.com

ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>

Then enable the modules proxy_http and proxy_html. They should already be installed on your machine. If not, install apache2-bin

sudo a2enmod proxy_http
sudo a2enmod proxy_html

Enable your new vhost:

sudo a2ensite sharetribe

and restart your apache

sudo service apache2 restart

 

You should now have access to your Sharetribe shop directly through myshop.com !

 

11) Email configurations

Once you start to configure your Sharetribe Instance, you will have to confirm your email address. Basically it will not work out of the box as you need to configure that part too. (You can byppass the email address confirmation by tweaking the database, but you probably want a production server isn’t it?).

I had quite some issues to do it and I had to follow a different path than what Sharetribe’s doc is suggesting. I am basically fully relying on Sendmail and directly configure it in the system rather than configuring the SMTP info in Sharetribe only.

Here is what I did to use my gmail SMTP.

First you need to turn on the “less secure” option in order to be able to use it. Simply do it over here.

Then run:

sudo apt-get install sendmail mailutils sendmail-bin

create the folder and configuration file:

sudo mkdir -m 700 /etc/mail/authinfo/
cd /etc/mail/authinfo/
sudo nano gmail-auth

and copy paste:

AuthInfo: "U:root" "I:YOUR GMAIL EMAIL ADDRESS" "P:YOUR PASSWORD"

User is root, I is your Gmail email and P is your password. (Keep the syntax with U:, I:, P:)

Then create the hash map:

sudo makemap hash gmail-auth < gmail-auth

now, configure your sendmail:

sudo nano /etc/mail/sendmail.mc

and paste just before the first “MAILER” definition line:

define(`SMART_HOST',`[smtp.gmail.com]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo/gmail-auth.db')dnl

Now rebuild the sendmail configuration and restart it

make -C /etc/mail
service sendmail restart

The final step is to configure Sharetribe to use Sendmail. You simply need to modify your config.yml file

nano /home/ubuntu/sharetribe/config/config.yml

and add:

mail_delivery_method: "sendmail"

Tadam!!

 

If you like this project, please thanks them directly or go with their paid package.Phew !! You now have a basic Sharetribe marketplace on your server. You will probably want to do so much more (payment gateway, etc..), feel free to check their documentation.

Gravatar

Loves to discover web-based apps to install on his own server@home and write articles about it

9 Comments:

Add a comment

Comments

Its working now!! OMG I didn't know I have to run those commands seperately. Thank you so much!
Written on Wed, 13 Jun 2018 18:30:34 by Krin
Hi, thank you for the tutorial. I ran into this error when I run this command RAILS_ENV=production bundle exec rake db:create RAILS_ENV=production bundle exec rake db:structure:load RAILS_ENV=production bundle exec rake ts:index RAILS_ENV=production bundle exec rake ts:start RAILS_ENV=production NODE_ENV=production bundle exec rake assets:precompile Error: Database 'sharetribe_production' already exists rake aborted! Don't know how to build task 'bundle' (see --tasks) /home/ubuntu/.rvm/gems/ruby-2.3.4/gems/rake-11.3.0/exe/rake:27:in `' /home/ubuntu/.rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in `eval' /home/ubuntu/.rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in `' (See full trace by running task with --trace) Could you please help me? Thanks!
Written on Wed, 13 Jun 2018 11:34:16 by Krin
Hi, You need to have google maps API to add in the database (You will find a API field. Simply add inside)
Written on Thu, 17 May 2018 04:50:58 by Karibu
Hello how can i add geolocation search like the paid version? Thanks
Written on Tue, 15 May 2018 13:37:37 by tips
Tks
Written on Fri, 11 May 2018 03:13:33 by Bruno Nascimento
Hi ! I got an error with mails : Sent mail to maxence.carpentier@musicalink.fr (12.1ms) {"tag":"delayed_job","free":"Job error: #\u003cErrno::ECONNREFUSED: Connection refused - connect(2) for \"localhost\" port 1025\u003e","type":"error","structured":{"job_name":"EmailConfirmationJob","args":{"email_id":1,"community_id":1}}} [Worker(host:185-163-125-236.onetsolutions.network pid:27747)] Job EmailConfirmationJob (id=14) (queue=default) FAILED (2 prior attempts) with Errno::ECONNREFUSED: Connection refused - connect(2) for "localhost" port 1025 2018-04-06T23:35:20 0200: [Worker(host:185-163-125-236.onetsolutions.network pid:27747)] Job EmailConfirmationJob (id=14) (queue=default) FAILED (2 prior attempts) with Errno::ECONNREFUSED: Connection refused - connect(2) for "localhost" port 1025 [Worker(host:185-163-125-236.onetsolutions.network pid:27747)] Job EmailConfirmationJob (id=14) (queue=default) REMOVED permanently because of 3 consecutive failures 2018-04-06T23:35:20 0200: [Worker(host:185-163-125-236.onetsolutions.network pid:27747)] Job EmailConfirmationJob (id=14) (queue=default) REMOVED permanently because of 3 consecutive failures [Worker(host:185-163-125-236.onetsolutions.network pid:27747)] 1 jobs processed at 3.1414 j/s, 1 failed 2018-04-06T23:35:20 0200: [Worker(host:185-163-125-236.onetsolutions.network pid:27747)] 1 jobs processed at 3.1414 j/s, 1 failed Do you know how to resolve it ? Thanks
Written on Fri, 06 Apr 2018 21:36:20 by Maxence
Hi Sam, you are inside the sharetribe folder you got from git when running npm install? What is your version of NodeJS? Hi Brian, for the harmony part, I did not cover this. (Useful for the calendar/availability) to work. I'll be happy to write more about it so feel free to share your findings. Thanks
Written on Tue, 20 Mar 2018 23:58:24 by karibu
how do i activate harmony production
Written on Tue, 20 Mar 2018 15:00:25 by brian
Getting stuck at npm install. I have the following error: npm WARN lifecycle undefined~postinstall: cannot run in wd %s %s (wd=%s) undefined cd client && npm install /mnt/c/Users/samue/sharetribe
Written on Tue, 20 Mar 2018 01:25:00 by sam