• Get In Touch
May 31, 2017

How to Install Spree Ecommerce on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Spree is a free and open source e-commerce store application. It is written in Ruby on Rails. Spree is fully featured modular application. It is responsive and fully customizable. It provides a personalized shopping experience to your users. It provides extensive product configuration possibilities so that user can customise the product by themselves. It also provides a comprehensive API for every aspect of the system. Spree is used by more than 45,000 shop owners worldwide.

In this tutorial, we will install Spree Ecommerce Store on CentOS 7 server.

Requirements

Spree Ecommerce Store does not require any special hardware requirements. All the required dependencies will be installed throughout the tutorial. You will need a minimal installation of CentOS 7 with root access on it. If you are logged in as a non-root user, you can run sudo -i to switch to root user.

Installing Spree

Before installing any package it is recommended that you update the packages and repository using the following command.

yum -y update

Spree is written in Ruby on Rails. Run the following command to install Ruby on your system. The YUM repository provides an old version of Ruby, you can use RVM or Ruby Version Manager to install the latest or specific version of Ruby on your server. Run the following command to add the GPG key of RVM on your server.

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

Now install RVM using following command.

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

Now logout from your terminal and login again before using rvm command. Fetch the list of Ruby using following command.

rvm list known

You will see following output:

# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.6]
[ruby-]2.3[.3]
[ruby-]2.4[.0]
ruby-head

Now install the latest version using the following command.

rvm install 2.4

Use the Ruby version using the following command.

rvm use 2.4

You can verify the version of Ruby using following command.

ruby -v

[root@liptan-pc ~]# ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]

Now you will need to install bundler. Bundler is a dependency manager for Ruby gem applications.

gem install bundler

Once you have installed bundler, you can continue with the installation of Rails. Run the following command to install Rails version 5.0.0 as this is the only version compatible with Spree 3.2.

gem install rails -v 5.0.0

You can now verify the that rails is installed using the following command.

rails -v

You will see following output.

[root@liptan-pc ~]# rails -v
Rails 5.0.0

You will also need to install ImageMagick library for manipulating images. Run the following command to install ImageMagick.

yum -y install ImageMagick

You will also need to install Node.js. Node.js is not available on YUM repository, you will need to install EPEL repository for this. Run the following command for same.

yum -y install epel-release && yum -y update

Now install Node.js using following command.

yum -y install nodejs

Now that we have Ruby, Rails and other dependencies are installed, you can run the following command to create a new Rails project.

cd /var
rails new myshop

You can use any name for your project at the place of myshop. Rails will now create a project in /var/myshop. Now switch to your newly created directory using the following command.

cd myshop

Now you will need to add Spree gems to the gemfile of your newly created project. Open the Gemfile through your favourite text editor. In this tutorial, we will use nano editor. If you do not have nano installed, you can run yum -y install nano. Open the Gemfile using following command.

nano Gemfile

Now copy and paste the following lines at the end of the file.

gem 'spree', '~> 3.2.1'
gem 'spree_auth_devise', '~> 3.2.0.beta'
gem 'spree_gateway', '~> 3.2.0.beta'

Save and exit the editor. Now install the application using the following command.

bundle install

Bundle will now download and install all the required dependencies. Once the application is installed, run the following commands to setup Spree.

rails g spree:install --user_class=Spree::User
rails g spree:auth:install
rails g spree_gateway:install

During the execution of the first command, it will ask you for the email address of the admin account. Provide the admin email and password for the creation of new admin user.

Spree is now installed and configured. You can see the web interface of your e-commerce store immediately by running the inbuilt web server using the following command.

rails server --binding=0.0.0.0

The above command will run the inbuilt server and will listen to port 3000. You can now browse the following address through your browser to see the frontend of your website. You can stop the server by pressing ctrl + c keys on keyboard.

You can set up a systemd service so that it can be managed as a service and can be automatically started on failures and boot time. Run the following command to create a systemd service file.

nano /etc/systemd/system/spree.service

Copy and paste the following code into the editor.

[Unit]
Description=Spree service
After=syslog.target network.target

[Service]
Type=simple
WorkingDirectory=/var/myshop
ExecStart=/usr/local/rvm/gems/ruby-2.4.0/wrappers/rails server
User=root
Group=root
Restart=always
RestartSec=9
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=spree

[Install]
WantedBy=multi-user.target

Now you can start Spree server and configure it to automatically start at boot time using following commands.

systemctl start spree
systemctl enable spree

To check if Spree service is started correctly, you can run the following command to check the status of the Spree service.

systemctl status spree

You should get output similar to shown below.

[root@liptan-pc myshop]# systemctl status spree
● spree.service - Spree service
   Loaded: loaded (/etc/systemd/system/spree.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2017-05-31 09:42:22 UTC; 9s ago
 Main PID: 23834 (ruby)
   CGroup: /system.slice/spree.service
           └─23834 puma 3.8.2 (tcp://0.0.0.0:3000) [myshop]

May 31 09:42:22 liptan-pc systemd[1]: Starting Spree service...
May 31 09:42:26 liptan-pc spree[23834]: => Booting Puma
May 31 09:42:26 liptan-pc spree[23834]: => Rails 5.0.3 application starting in development on http://localhost:3000
May 31 09:42:26 liptan-pc spree[23834]: => Run `rails server -h` for more startup options
May 31 09:42:26 liptan-pc spree[23834]: Puma starting in single mode...
May 31 09:42:26 liptan-pc spree[23834]: * Version 3.8.2 (ruby 2.4.0-p0), codename: Sassy Salamander
May 31 09:42:26 liptan-pc spree[23834]: * Min threads: 5, max threads: 5
May 31 09:42:26 liptan-pc spree[23834]: * Environment: development
May 31 09:42:26 liptan-pc spree[23834]: * Listening on tcp://0.0.0.0:3000
May 31 09:42:26 liptan-pc spree[23834]: Use Ctrl-C to stop

Instead of using the application on Port 3000, you can use Apache to run on port 80. This way the main application will run on port 3000, and Apache will work as a reverse proxy.

yum -y install httpd

Now start the Apache web server and enable it to automatically start at boot time using the following commands.

systemctl start httpd
systemctl enable httpd

Create a new virtual host file using the following command.

nano /etc/httpd/conf.d/shop.yourdomain.com.conf

Replace shop.yourdomain.com with your actual domain. Now copy and paste the following lines into the file.

<VirtualHost *:80>  
    ServerName yourdomain.com
    ServerAdmin me@liptanbiswas.com
    ProxyPreserveHost On
    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/
    TransferLog /var/log/httpd/shop.yourdomain.com_access.log
    ErrorLog /var/log/httpd/shop.yourdomain.com_error.log
</VirtualHost>

In the above configuration change shop.yourdomain.com to your actual domain. Once done, you will have to restart your Apache server so that the changes made can take effect.

systemctl restart httpd

Now you will need to disable your SELinux because reverse proxy creates errors with SELinux policies. To temporary disable SELinux without restarting the server, run the following command.

setenforce 0

To completely disable the SELinux you will need to edit /etc/selinux/config file.

nano /etc/selinux/config

Find the following line:

SELINUX=enforcing

Change it to:

SELINUX=disabled

Now you will need to reboot your server so that the new configuration can take effect. Now you can start the Spree service if not started already using the following command.

systemctl start spree

You can now browse the following URL in your favourite browser.

http://shop.yourdomain.com

You will now see the storefront of your site.

HP_NO_IMG/data/uploads/users/96ef1f90-83ed-46f0-9b58-aa6ee50a1451/654504460.png” alt=”” />

To access the admin panel of your site, you can go to http://shop.yourdomain.com/admin.

Conclusion

In this tutorial, we have learned how to install Spree Ecommerce Shop on your CentOS 7 server instance. You can now use the shop to sell the goods online and to increase your business.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]