FreeBSD Adding Spree E-Commerce to Ruby on Rails application

Spree Commerce created by Sean Schofield and now developed by Spark Solutions is a modular and versatile open source ecommerce platform that allows easy integration with any third-party integration. Spree commerce is built with Ruby on Rails and as a solution for merchants using e-commerce platforms, because Spree Commerce is open source, modular and API-based so it is very easy and safe to use.

Spree's open source b2b ecommerce platform eCommerce is aimed at merchants running online businesses, which are currently growing rapidly. Each new major release consists of several different gems and modules. Spree also uses the ImageMagick library to process and manipulate product images, thereby attracting consumers to view and buy.

Currently, Spree Commerce can not only be accessed via computer, its very complete features are very comfortable to use on mobile handheld devices. Not only that, Spree Commerce's open source ecommerce software uses the Open Graph protocol to improve the way products are shared on social media channels such as LinkedIn, Instagram, Facebook and Twitter.

In short, Spree Commerce is a comprehensive e-commerce framework that offers scalable open source solutions to entrepreneurs. More simply, it is simply a collection of free code that web builders can use to shape and build beautiful digital storefronts.

As an open source E-commerce solution, Spree Commerce offers a unique experience for those building a profitable online Store presence. Unlike other hosted E-commerce solutions for building your online store, Spree commerce gives you a lot of freedom. Basically you can build any suitable website for your trading venture, as long as you are comfortable with the coding language.

Looking at it positively, Spree Commerce offers a huge amount of in-depth design customization, with a wide range of features and payment gateways to explore. Instead, you need a little builder knowledge to start building your ecommerce website.



In this article, we will explain the process of installing and configuring Spree Commerce with "Ruby on Rails" on a FreeBSD machine and the entire content of this article was written using the following applications and utilities:

Operating system: FreeBSD 13.3
IP Addres: 192.168.5.2
Name server: ns3
Ruby version: ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [amd64-freebsd13]
Bundler version: Bundler 2.3.6
Gem version: gems 3.5.7
Database: Postgresql15-server
Web Server: Apache24 (optional)
Database: Postgresql15-server, SQLite3 or MySQL


1. Installation Spree Commerce

Before we start installing Spree Commerce, make sure all the applications above are installed properly on your FreeBSD machine. Otherwise, don't expect to be able to run Spree Commerce on FreeBSD. If you have difficulty installing Ruby, read our previous article.

FreeBSD Installation Ruby Gemfile and Bundle With Path Environemnt

One of the drawbacks of FreeBSD is that the Spree Commerce repository is not available in PKG packages or system ports. You can download Spree from the Github repository. Run the following command to clone Spree Commerce.

/usr/local/www
root@ns3:~ # cd /usr/local/www
root@ns3:/usr/local/www # git clone https://github.com/spree/spree.git
Next, you create users and groups for Spree Commerce, this is so that Spree Commerce can run smoothly and not collide with other Ruby applications.

Create user: spree and group: spree
root@ns3:/usr/local/www # pw add group spree
root@ns3:/usr/local/www # pw add user -n spree -g spree -s /sbin/nologin -c "spree user"
Run the chown and chmod commands to give permissions and ownership to Spree Commerce.

Create permissions and ownership
root@ns3:/usr/local/www # chown -R spree:spree /usr/local/www/spree/
root@ns3:/usr/local/www # chmod -R 775 /usr/local/www/spree


2. Setup Spree Commerce

The next step we will configure Spree Commerce. In this section the discussion is a bit long, don't skip any configurations or scripts.

a. Setup Bundler

Before you install the gem, run the Initialize Bundler command.

/usr/local/www/spree
root@ns3:/usr/local/www # cd spree
root@ns3:/usr/local/www/spree # rm Gemfile
root@ns3:/usr/local/www/spree # bundle init

b. Add Spree gems to your Gemfile

In this section, we install the spree gem so you can use its extension generator. In your spree directory, open the Gemfile file and type the script below in the Gemfile file.

/usr/local/www/spree
root@ns3:/usr/local/www/spree # ee Gemfile
# frozen_string_literal: true
source "https://rubygems.org"

gem "rails"
gem "spree"
gem "spree_backend"
gem "spree_frontend"
gem "spree_emails"
gem "spree_sample"
gem "spree_auth_devise"
gem "spree_gateway"
gem "spree_i18n" 
# only needed for MacOS and Ruby 3+
gem "sassc", github: 'sass/sassc-ruby', branch: 'master'
gem "railties"

c. Install gems Gemfile

Then install the Spree Commerce extension dependencies.

/usr/local/www/spree
root@ns3:/usr/local/www/spree # bundle install
root@ns3:/usr/local/www/spree # bundle update
After that, in the /usr/local/www/spree/bin directory, you run the command below.

/usr/local/www/spree/bin
root@ns3:/usr/local/www/spree # bin/bundle_ruby.sh
root@ns3:/usr/local/www/spree # bin/build.sh
root@ns3:/usr/local/www/spree # git config --global --add safe.directory /usr/local/www/spree
root@ns3:/usr/local/www/spree # rake db:migrate

d. Creates a new Rails application

Run the `rails new` Command to create a new Rails application with the default directory structure and configuration on the path you specified i.e. /usr/local/www/spree/weblog.

/usr/local/www/spree
root@ns3:/usr/local/www/spree # rails new /usr/local/www/spree/weblog
root@ns3:/usr/local/www/spree # rails _7.1.3.2_ new weblog
root@ns3:/usr/local/www/spree # rails new weblog --api
root@ns3:/usr/local/www/spree # rails new weblog --skip-action-mailer
The above command will create a new rail directory named "weblog".

e. Install generators

The next step is to run the installation generator on the Rails weblog that you created above. This command is used to set up Spree Commerce. Before you run the installation generator, add the script below to the Gemfile file in the /usr/local/www/spree/weblog directory.

/usr/local/www/spree/weblog
root@ns3:/usr/local/www/spree # cd weblog
root@ns3:/usr/local/www/spree/weblog # ee Gemfile
gem "spree"
gem "spree_backend"
gem "spree_frontend"
gem "spree_emails"
gem "spree_sample"
gem "spree_auth_devise"
gem "spree_gateway"
gem "spree_i18n" 
# only needed for MacOS and Ruby 3+
gem "sassc", github: 'sass/sassc-ruby', branch: 'master'
gem "railties"
Run the installation generator on the Rails weblog.

/usr/local/www/spree
root@ns3:/usr/local/www/spree/weblog # bundle install
root@ns3:/usr/local/www/spree/weblog # bundle update
/usr/local/www/spree/weblog
root@ns3:/usr/local/www/spree/weblog # bin/rails g spree:install --user_class=Spree::User
root@ns3:/usr/local/www/spree/weblog # bin/rails g spree:backend:install
root@ns3:/usr/local/www/spree/weblog # bin/rails g spree:frontend:install
root@ns3:/usr/local/www/spree/weblog # bin/rails g spree:auth:install
root@ns3:/usr/local/www/spree/weblog # bin/rails g spree_gateway:install
In the /usr/local/www/spree/weblog directory, run the Run bin/setup command.

/usr/local/www/spree/weblog
root@ns3:/usr/local/www/spree/weblog # bin/setup

f. Installation options

By default, when you run the installation generator command, it will automatically run the migration and add the seed. This can be disabled using the command.

/usr/local/www/spree/weblog
root@ns3:/usr/local/www/spree/weblog # bin/rails g spree:install --migrate=false --sample=false --seed=false
You also run the command below.

/usr/local/www/spree/weblog
root@ns3:/usr/local/www/spree/weblog # bin/rake railties:install:migrations
root@ns3:/usr/local/www/spree/weblog # bin/rails db:migrate
root@ns3:/usr/local/www/spree/weblog # bin/rails db:seed
root@ns3:/usr/local/www/spree/weblog # bin/rake spree_sample:load

g. Mounting the Spree Spree Commerce engine

When you run the rails g spree:install command it will automatically install Spree, installing the Spree::Core::Engine component by automatically inserting this line into config/routes.rb.

/usr/local/www/spree/weblog
root@ns3:/usr/local/www/spree/weblog # mount Spree::Core::Engine, at: '/'


3. Run Spree Commerce

After you have finished carrying out all the Spree Commerce configuration steps above, the next step is to run Spree Commerce. Type the following command in your shell menu.

/usr/local/www/spree/weblog
root@ns3:/usr/local/www/spree/weblog # rails s -b 192.168.5.2
Open your favorite web browser, for example Google Chrome and type the command "http://192.168.5.2:3000/admin", the Login menu will appear. If you do not change the user and password, by default the Spree Commerce user and password are

user: spree@example.com
password: spree123



After you have successfully entered Spree Commerce, your monitor screen will appear as shown in the image below.





In this tutorial, we have explained how to install and configure the Spree Commerce e-commerce platform on a FreeBSD server. You can continue to hone and explore all the features of Spree Commerce, so you can use it to sell goods and products online and improve your business.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post