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.
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.
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.
[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.
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.
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.
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.
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 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.
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
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: Starting Spree service... May 31 09:42:26 liptan-pc spree: => Booting Puma May 31 09:42:26 liptan-pc spree: => Rails 5.0.3 application starting in development on http://localhost:3000 May 31 09:42:26 liptan-pc spree: => Run `rails server -h` for more startup options May 31 09:42:26 liptan-pc spree: Puma starting in single mode... May 31 09:42:26 liptan-pc spree: * Version 3.8.2 (ruby 2.4.0-p0), codename: Sassy Salamander May 31 09:42:26 liptan-pc spree: * Min threads: 5, max threads: 5 May 31 09:42:26 liptan-pc spree: * Environment: development May 31 09:42:26 liptan-pc spree: * Listening on tcp://0.0.0.0:3000 May 31 09:42:26 liptan-pc spree: 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.
shop.yourdomain.com with your actual domain. Now copy and paste the following lines into the file.
<VirtualHost *:80> ServerName yourdomain.com ServerAdmin firstname.lastname@example.org 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.
To completely disable the SELinux you will need to edit
Find the following line:
Change it to:
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.
You will now see the storefront of your site.
To access the admin panel of your site, you can go to
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.