Setting up Saleor on C9

Saleor is an open source storefront or e-commerce framework written in Python. In fact, it is one of the few storefronts that is written in Python that's listed on Top Open-Source E-Commerce Platforms webpage.
Setting up Saleor on C9

Saleor offers an easy customization and clear architecture design for developers to extend and make it their own. It is said to be scalable and gives developers and managers building blocks to make it into an enterprise level system. Saleor runs on Python 2.7, Python 3.5 and above. It is built on top of Django modules running of PostgreSQL 9.4 and above. It comes with GraphQI and Elastic search with an optimized SEO normalize for fast indexes and searches within the system and external search engines. Because the minimum requirements for Saleor are Python 3.5 and PostgreSQL 9.4, setting up Saleor on C9 is not very straightforward as our local install. In fact, we have to upgrade from python 3.4 and PostgreSQL 9.3 that is running on C9 to at least the minimum requirements for Saleor.

Setting up Saleor in your C9 environment

First, create a C9 Workspace as seen in the screenshot below:

Creating a c9 workspace for saleor

Once your workspace is ready, you need to install webpack globally into your system by executing the following command:

sudo npm i webpack -g
Setting up Python 3.6 on C9

The next step is to install python 3.6 and its development dependencies. To do this, execute the following commands:

sudo add-apt-repository ppa:jonathonf/python-3.6 -y
sudo apt-get update -y
sudo apt-get install python3.6 python3.6-dev -y

After installing Python 3.6, we're going to set up a python 3.6 virtualenv and install all of Saleor's dependencies in it. The following command will do so:

sudo pip install virtualenv
virtualenv .
bin/pip install -r requirements.txt
Setting up PostgreSQL 9.6 on C9

Afterwards, remove PostgreSQL 9.3 by executing the following command:

sudo apt-get remove postgresql

Then, install PostgreSQL 9.6 by doing the following:

sudo su -c "echo \"deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main 9.6\" > /etc/apt/sources.list.d/postgresql.list"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get install -y postgresql-9.6

By default, saleor is configured to have a user called saleor with the password saleor that can access the database saleor.

If you already have a database and a user you wish to use, you can edit the database credentials that is found in the settings.py file. In addition, the saleor database user requies super privilliges to create extension files in the database system.

Before we can set up our database and database user, make sure it is running by executing the following command:

sudo service postgresql restart
sudo -u postgres createuser --superuser saleor
sudo -u postgres createdb saleor
sudo -u postgres psql -c "alter user saleor with encrypted password 'saleor'"

Afterwards, execute the run the following command to initialize and migrate the database schema:

bin/python manage.py migrate
Installing frontend dependencies and asset

Finally, execute the following command to complete the setup:

npm install
npm run build-assets

Running and serving Saleor on C9

Before we start the server, we need to add a secret key to the application. We can run the following command to export the application secret key into our C9 environment:

export SECRET_KEY='<mysecretkey>'
You can also set the application secret key direct in the application by editting settings.py on line 128.

Run the following command to start the server:

bin/python manage.py runserver 0.0.0.0:8080

After previewing your running application, you may notice that you're getting the following error:

Invalid HTTP_HOST header: 'saleor-<username>.c9users.io'. You may need to add 'saleor-<username>.c9users.io' to ALLOWED_HOSTS.

Export the allowed hosts into your C9 environment by running the following command:

export ALLOWED_HOSTS=$C9_HOSTNAME
You can also set the allowed hosts directly in the application by editting settings.py on line 294.

That's it. Enjoy your new Saleor instance. If you have any issues, please leave a comment on this page.

Go Back
Menu
×