Self-hosted Sharetribe Go Community Edition on Ubuntu
The instructions provided in this article here are for an all-in-one Sharetribe Go CE running on Ubuntu in production mode. While this may not be an ideal available & scalable scenario, it is good for small or hobby scenarios.
Quick Introduction
Sharetribe is a multi-marketplace model and hence it follows a subdomain approach by default. For example, buynsell.example.com where buynsell is the marketplace (referred to as a community) and example.com is the domain. This subdomain is called an ident. During a new marketplace setup, Shatetribe uses the marketplace name provided in the form to create the ident, which is then combined with the domain to create the marketplace URL.
The subdomain approach makes the initial setup somewhat simpler, especially with steps such as marketplace creation and email verification.
One can later update the installation to use the domain only, if required.
Before you begin
An Ubuntu 20.04 or later VM/VPS
A subdomain mapped to the IP of the VM/VPS. This will be the URL. E.g. buynsell.example.com
Prepare for Sharetribe pre-requisites installation
Install general pre-requisites
Start by installing the following packages. Most of them may be already installed on a fresh Ubuntu VM.
sudo apt install -y git curl wget openssl
Install RVM
RVM is required to install a specific version of Ruby. In this step, you are adding the gpg key, installing RVM using curl and loading RVM using the source command. (There are 3 separate commands)
gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
Install NVM
To install a specific version of Node (as required by Sharetribe) we will use NVM. In this step, you will install NVM using curl & bash.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
To use NVM a shell reload is required i.e. you have to log out and log in. Alternatively, you can run the commands presented in the output of the curl command. See the example screenshot below:
Install & Configure NGINX
NGINX will act as a reverse proxy to access Sharetribe which is served on port 3000. Without this, you will have to mention the port number along with the URL for it to work out of the box.
sudo apt install -y nginx
Once installed, edit the /etc/nginx/sites-available/default file to reflect the following configuration. Replace buynsell.example.com with your own URL. Save the file.
server {
listen 80;
server_name buynsell.example.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
proxy_pass http://lvh.me:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
sudo service nginx restart
This is a very basic configuration of NGINX to access the URL normally. Ensure the URL works, showing the NGINX welcome page.
Install Sharetribe pre-requisites
Before continuing with the rest of the steps, update the package repository.
sudo apt update
Install Ruby
The current version used is 2.7.5. Other versions are not tested and may cause issues.
rvm install 2.7.5
Install gems
Sharetribe requires the bundler and the foreman gems.
gem install bundler
gem install foreman
Install Node & NPM
Continuing with the specific version requirements, the Node version should be 10.15.3. Anything else throws an error.
nvm install 10.15.3
Install additional requirements
Sharetribe requires ImageMagick and the Sphinx search server.
Memcached is required for object caching. While this is not mentioned in the general installation instructions, you will see DalliErrors without this.
Sharetribe uses Sendmail as the default mail delivery method in production. (NOTE: Sendmail will require additional configuration post installation to work, such as setting it up with an SMTP provider. It is not part of this article)
sudo apt install -y imagemagick sphinxsearch memcached sendmail
Install & Configure MySQL
Sharetribe requires MySQL 5.7. Newer Ubuntu distributions' repositories come with MySQL 8 as the default version.
Look for instructions online on how to install MySQL 5.7 using the MySQL Apt Repository.
Secure MySQL & create a user for the production db
It is highly recommended to secure the installation of MySQL, you can do so by running mysql_secure_installation.
Next, create a user in MySQL to be used for the sharetribe_production database. Do not create the database, it will be created by the bundle command later.
It is recommended to create separate credentials for separate environments and not use the root credentials.
Install additional MySQL packages
MySQL database development files in the default-libmysqlclient-dev package are required as well to ensure the successful compilation of the mysql2 0.4.10 extension. Without this, the bundle install step will fail.
sudo apt-get install default-libmysqlclient-dev -y
Install Sharetribe
Start by cloning the Sharetribe repo and checking out a release. In this example, we are using the latest release i.e. v10.3.0.
git clone https://github.com/sharetribe/sharetribe.git
cd sharetribe
git checkout latest
Install Gems
Run the following command to install all the gems (ensure you are in the project root).
bundle install
Install Node Modules
npm install
Post-install Configuration
In this step, you will create the general config and database config files from the sample and configure them.
Start by copying the sample files.
cp config/database.example.yml config/database.yml
cp config/config.example.yml config/config.yml
Update database credentials
Edit the config/database.yml file to update the user for the sharetribe_production database. Replace the username and password values with your values. If you are not running any other environment on the same machine, setting the credentials for other environments is not required.
.....
production:
adapter: mysql2
database: sharetribe_production
encoding: utf8
username: dbuser
password: dbpassword
host: localhost
.....
Configure domain
This part is important. In this step, we will set the domain to be used for our production instance. Sharetribe configuration requires that only the top domain is mentioned. So, even though our URL is going to be buynsell.example.com, only example.com is written as the value. buynsell will be added to this top domain during the new marketplace creation step.
Edit the config/config.yml file and add the domain parameter as shown below:
production:
domain: example.com
Configure Storage Service
For Sharetribe in the production environment, the default active_storage_service is set to amazon. Before we can run, we have to either provide AWS S3 credentials or change the storage service type to local. In this example, we are changing it to local.
For information on configuring for AWS S3 read this.
Edit the config/config.yml file and add the following under production. Remember to save the file.
production:
domain: example.com
active_storage_service: local
Configure Email
Email verification is set to true by default for Sharetribe in production. So the new marketplace creation step will remain incomplete unless the email address used during the creation is verified. Hence, this requires that there is a working mail delivery system.
Ensure that Sendmail is working before continuing, meaning you can send and receive emails to your mailbox from this VM.
Alternatively, you can disable email verification temporarily during the initial setup and enable it later. To disable, edit config/config.yml and add the following under production. In this example, we are disabling it.
production:
domain: example.com
active_storage_service: local
skip_email_confirmation: true
Prepare the production environment
Generate and set a secret key
To generate the secret run the following command:
rake secret
Edit the config/config.yml file and add the secret key under production.
production:
domain: example.com
active_storage_service: local
skip_email_confirmation: true
secret_key_base: 311d903beac311d903beac311d903beac311d903beac
Create and initialize the production database
RAILS_ENV=production bundle exec rake db:create
RAILS_ENV=production bundle exec rake db:structure:load
Run the Sphinx index and start Sphinx
RAILS_ENV=production bundle exec rake ts:index
RAILS_ENV=production bundle exec rake ts:start
Precompile assets
RAILS_ENV=production NODE_ENV=production bundle exec rake assets:precompile
Start Sharetribe
Invoke the delayed job worker
FYI, this command runs in the foreground.
RAILS_ENV=production bundle exec rake jobs:work
Start rails server
In a new terminal, run rails in production to run Sharetribe. It listens on any IP on port 3000. This command also runs in the foreground.
bundle exec rails server -e production
Creating the marketplace
Open a browser and navigate to your domain. You will be presented with the Set up your marketplace page. Enter all the details including a valid email address and ensure the Marketplace name is exactly the same as the subdomain part of your URL. For example, if the URL is buynsell.example.com enter buynsell. You can change the marketplace name later, entering anything else here will result in Sharetribe creating a marketplace domain that may not exist and hence show an error (Unable to connect).
Click Save changes when done.
If everything went well, you should be redirected to a logged-in page (if you had email confirmation disabled) or a Confirm your email address page (default behavior). Confirm your email address to complete the process.
The admin page can be accessed by appending /admin to the URL. E.g. buynsell.example.com/admin.
You now have Sharetribe deployed in production mode as an all-in-one solution.
Leave me a message / comment if you find something is out of place.
Subscribe to my newsletter
Read articles from Sangram Rath directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by