Community Blog How to Install Spree E-commerce on Alibaba Cloud

How to Install Spree E-commerce on Alibaba Cloud

In this tutorial, you will learn how to set up the Spree e-commerce platform on Alibaba Cloud.

By Sajid Qureshi, Alibaba Community Blog author

In this tutorial, you'll be learning how to set up Spree on Alibaba Cloud. So, what's Spree? Spree is a free-to-use, open-source API driven e-commerce framework solution. Spree is written in Ruby on Rails, and it is a completely modular application.

It is fully responsive and can provide a completely personalized experience. A user can customize the product himself on this e-commerce platform. Many well known and successful brands and startups are using Spree Commerce for their e-commerce businesses. It is designed to make programming commerce applications easier by making several assumptions about what most developers need to get started.


For this tutorial, you'll need the following:

  1. You must have an Alibaba Cloud Elastic Compute Service (ECS) instance activated and have verified a valid payment method. If you are a new user, you can get a free account. If you don't know about how to set up your ECS instance, you can refer to this tutorial or this quick-start guide. Note that, for this tutorial, your ECS instance must have at least 1GB RAM and 1 Core processor.
  2. A domain name registered from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain nameserver records.
  3. A root user.

Setting up Your Server

Before installing any packages on your Alibaba Cloud instance, it's recommended that you to update all the available packages and repository using the yum -y update command.

Given that Spree is written in Ruby on Rails, you'll need to install Ruby on the system before you can install Spree. For this tutorial, we will be using the RVM (Ruby Version Manager) to install the latest version of Ruby. Add the GPG key of RVM to your system using the following command.

gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Once the key is added, you can proceed further and install RVM using the following command:

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

Now log out and then log bak in again to your system, and run the rvm list known command to list Ruby. As an output, you should see a list of Ruby versions, which should look something like this:

# MRI Rubies
[ruby-]1.8.7[-head] # security released on head

Now you'll want to install the latest stable version using the rvm install 2.6 command. Note that it may take a few moments for the installation to be complete. This is normal. Once it's complete, run the rvm use 2.6 command to use this Ruby version.

Through the above steps, you have installed Ruby on your server, but this Ruby installation won't work properly unless you also install bundler. Bundler is dependencies manager for Ruby. Execute the gem install bundler command to install bundler.

Next, you'll need to install Rails version 5+ because Spree 3.7 supports only version Rails 5.2.2. To do this, run the gem install rails -v 5.2.2 command. Next, you can also verify this installation by checking the Rails version using the rails -v command.

ImageMagick is a free library, which is used widely for displaying and converting images. You'll need to install the ImageMagick library. You can do so with the yum -y install ImageMagick command. Next, you'll also need to install node.js before using Spree. Add the EPEL repository to your system and then update the system using the following command:

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

Next, run the yum -y install nodejs command to install Node.js.

Installing Spree

Now that you have installed all your needed dependencies, including Ruby, Rails, Node.js, so on, you'll want to create a new Rails project in order to install spree. You can do so with the cd /var && rails new spreeshop command. For this, you can use any name of your project instead of spreeshop. Next, change your current directory to this newly created project using the cd spreeshop command.

Following this, you'll have to add the Spree gems to the Gem file of our new Rails project. You can do so using any text editor. However, for this tutorial, you'll be using the nano text editor. You can also install it using the yum -y install nano command. After all that's complete, open Gem file using the nano Gemfile command, and add the following content into the file at the end.

gem 'spree', '~> 3.7.0'
gem 'spree_auth_devise', '~> 3.5'
gem 'spree_gateway', '~> 3.4'

Save the file and exit from the text editor. Then, install the application using the bundle. Run the bundle install command. It will download and install the application for you. Then, after the Spree application is installed, you will need to set up spree using the following commands.

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

You'll be prompted for an admin email. For this, you can simply enter the email address and password of admin and continue. Now you have installed Spree e-commerce on your Alibaba Cloud instance.

With this, you can manage it as a service so that it can be automatically started on failures and during boot times. In order to do so, you will need to create a systemd service file using any text editor. For this, enter the nano /etc/systemd/system/spree.service command, and add the following content into the file:

Description=Spree service
After=syslog.target network.target

ExecStart=/usr/local/rvm/gems/ruby-2.6.0/wrappers/rails server

Save the file and exit from the text editor.

Last, you can start it and enable it to automatically start a boot time using the following command.

systemctl start spree
systemctl enable spree

Then, you can also check the status of Spree service using the systemctl status spree command. Following this, you should see the status active(running) indicated in a green color.

Create a Virtual Host

By default, Spree listens on port number 3000. But, for this tutorial, we will be using the Apache web server as a reverse proxy, so that it will run on port 80. For this, you'll need to install apache web server using the yum -y install httpd command.

Then, once apache is installed, start the Apache web server and enable it to launch at the boot time as we have done earlier using the following command:

systemctl start httpd
systemctl enable httpd

Next, you'll need to create a new virtual host file using the following command:

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

And, you'll need to add the following content to the configuration file. Note that, of course, you'll need to replace ServerName, ServerAdmin, and yourdomain.com with your actual server name, admin, and web address.

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

Once copied over, save the file and exit from the text editor. Next, you'll want to restart the Apache web server to apply these changes using the systemctl restart httpd command.

Following this, you'll want to disable SELinux services, otherwise the reverse proxy will generate some errors with SELinux policies. You can temporarily disable your SELinux using the setenforce 0 command without rebooting your server.

Open up your favorite web browser and visit http://yourdomain.com and you should see the Spree e-commerce store of your site. Change the address to match your actual one, of course. If you want to access the admin panel of your site then visit http://yourdomain.com/admin.

Now, you have a fully functional Spree application up and running. Now you can manage, modify and extend your Spree application.

Configuring Taxes

It is very challenging to manage taxation settings in an e-commerce store—particularly, when you sell a variety of types of goods. But, the Spree e-commerce platform makes managing taxation settings simple and easy. You can follow the steps below to get things up and running:

  1. To access your store's existing Tax Categories, go to your Admin Interface, click Configuration, and then Tax Categories.
  2. Edit existing Tax Categories by clicking the edit icon next to each in the list.
  3. You can also remove a Tax Category by clicking the delete icon next to the category, then clicking OK to confirm.
  4. To create a new Tax Category, click the New Tax Category button. You'll be asked to enter a Name, optional description finish it and click on the Create button.


Spree uses roles to define user's permissions on your website. You can limit your user's rights on your site by defining roles. Follow the steps below to create a new role:

  1. To open Roles tab, extend the Configuration drop-down menu to find Roles.
  2. Click the New Role button, which is placed in the right upper corner of the screen.
  3. Input a name for the certain role and press the Update button.
  4. (Optional) You can delete it by clicking Delete button.


In this tutorial, you have learned how to install and configure the Spree e-commerce platform on your CentOS 7 server. You have also installed Ruby, Rails, and Apache web server on your CentOS 7 server. Hopefully, through this tutorial, you now have the knowledge to work with Spree and use it to sell goods and products online and increase your business.

1 0 0
Share on

Alibaba Clouder

2,600 posts | 750 followers

You may also like


5106445535045136 February 22, 2022 at 1:04 pm

Such an informative blog was shared, it was a real treat to read this blog. We also shared the same blog with detailed information, if you are interested to know more about "Sphinx on Ruby on Rails Application with Spree" then must visit our blog:https://www.bluebash.co/blog/thinking-sphinx-on-ruby-on-rails-application-with-spree/