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:
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.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[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.5]
[ruby-]2.5[.3]
[ruby-]2.6[.0]
ruby-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.
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:
[Unit]
Description=Spree service
After=syslog.target network.target
[Service]
Type=simple
WorkingDirectory=/var/spreeshop
ExecStart=/usr/local/rvm/gems/ruby-2.6.0/wrappers/rails server
User=root
Group=root
Restart=always
RestartSec=9
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=spree
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.
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
</VirtualHost>
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.
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:
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:
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.
2,599 posts | 762 followers
FollowAlibaba Cloud MVP - January 17, 2020
ApsaraDB - October 24, 2018
Alibaba Clouder - February 20, 2019
AlibabaCloud_Network - December 19, 2018
Alibaba Clouder - November 10, 2020
ApsaraDB - July 10, 2019
2,599 posts | 762 followers
FollowVPN Gateway is an Internet-based service that establishes a connection between a VPC and your on-premise data center.
Learn MoreSave egress traffic cost. Eliminate all complexity in managing storage cost.
Learn MoreGet started on cloud with $1. Start your cloud innovation journey here and now.
Learn MoreAlibaba Cloud e-commerce solutions offer a suite of cloud computing and big data services.
Learn MoreMore Posts by Alibaba Clouder
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/