Skip to content

Installing

Akram El Assas edited this page Jun 15, 2023 · 1 revision

Below are the installation instructions on Ubuntu Linux.

Prerequisites

  1. Install git, Node.js, nginx, MongoDB and mongosh.

  2. Configure MongoDB:

mongosh

Create admin user:

db = db.getSiblingDB('admin')
db.createUser({ user: "admin" , pwd: "PASSWORD", roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]})

Replace PASSWORD with a strong password.

Secure MongoDB:

sudo nano /etc/mongod.conf

Change configuration as follows:

net:
  port: 27017
  bindIp: 0.0.0.0

security:
  authorization: enabled

Restart MongoDB service:

sudo systemctl restart mongod.service
sudo systemctl status mongod.service

Instructions

  1. Clone wexCommerce repo:
cd /opt
sudo git clone https://github.com/aelassas/wexcommerce.git
  1. Add permissions:
sudo chown -R $USER:$USER /opt/wexcommerce
sudo chmod -R +x /opt/wexcommerce/__scripts
  1. Create deployment shortcut:
sudo ln -s /opt/wexcommerce/__scripts/wc-deploy.sh /usr/local/bin/wc-deploy
  1. Create wexCommerce services:
sudo cp /opt/wexcommerce/__services/wexcommerce.service /etc/systemd/system
sudo systemctl enable wexcommerce.service

sudo cp /opt/wexcommerce/__services/wexcommerce-backend.service /etc/systemd/system
sudo systemctl enable wexcommerce-backend.service

sudo cp /opt/wexcommerce/__services/wexcommerce-frontend.service /etc/systemd/system
sudo systemctl enable wexcommerce-frontend.service
  1. Add /opt/wexcommerce/api/.env file:
NODE_ENV = production
WC_PORT = 4004
WC_HTTPS = false
WC_PRIVATE_KEY = /etc/ssl/wexcommerce.key
WC_CERTIFICATE = /etc/ssl/wexcommerce.crt
WC_DB_HOST = 127.0.0.1
WC_DB_PORT = 27017
WC_DB_SSL = false
WC_DB_SSL_KEY = /etc/ssl/wexcommerce.key
WC_DB_SSL_CERT = /etc/ssl/wexcommerce.crt
WC_DB_SSL_CA = /etc/ssl/wexcommerce.ca.pem
WC_DB_DEBUG = true
WC_DB_APP_NAME = wexcommerce
WC_DB_AUTH_SOURCE = admin
WC_DB_USERNAME = admin
WC_DB_PASSWORD = PASSWORD
WC_DB_NAME = wexcommerce
WC_JWT_SECRET = PASSWORD
WC_JWT_EXPIRE_AT = 86400
WC_TOKEN_EXPIRE_AT = 86400
WC_SMTP_HOST = in-v3iljet.com
WC_SMTP_PORT = 587
WC_SMTP_USER = USER
WC_SMTP_PASS = PASSWORD
WC_SMTP_FROM = admin@wexcommerce.com
WC_ADMIN_EMAIL = admin@wexcommerce.com
WC_CDN_PRODUCTS = /var/www/cdn/wexcommerce/products
WC_CDN_TEMP_PRODUCTS =  /var/www/cdn/wexcommerce/temp/products
WC_BACKEND_HOST = http://localhost:8002/
WC_FRONTEND_HOST = http://localhost:8001/
WC_DEFAULT_LANGUAGE = en
WC_DEFAULT_CURRENCY = $

You must configure the following options:

WC_DB_PASSWORD
WC_SMTP_USER
WC_SMTP_PASS
WC_SMTP_FROM
WC_ADMIN_EMAIL
WC_BACKEND_HOST
WC_FRONTEND_HOST

If you want to enable SSL, You must configure the following options:

WC_HTTPS = true
WC_PRIVATE_KEY
WC_CERTIFICATE
  1. Add /opt/wexcommerce/backend/.env file:
NEXT_PUBLIC_WC_API_HOST = http://localhost:4004
NEXT_PUBLIC_WC_PAGE_SIZE = 30
NEXT_PUBLIC_WC_CDN_PRODUCTS = http://localhost/cdn/wexcommerce/products
NEXT_PUBLIC_WC_CDN_TEMP_PRODUCTS = http://localhost/cdn/wexcommerce/temp/products
NEXT_PUBLIC_WC_APP_TYPE = backend

You must configure the following options:

NEXT_PUBLIC_WC_API_HOST
NEXT_PUBLIC_WC_CDN_PRODUCTS
NEXT_PUBLIC_WC_CDN_TEMP_PRODUCTS
  1. Add /opt/wexcommerce/frontend/.env file:
NEXT_PUBLIC_WC_API_HOST = http://localhost:4004
NEXT_PUBLIC_WC_PAGE_SIZE = 30
NEXT_PUBLIC_WC_CDN_PRODUCTS = http://localhost/cdn/wexcommerce/products
NEXT_PUBLIC_WC_CDN_TEMP_PRODUCTS = http://localhost/cdn/wexcommerce/temp/products
NEXT_PUBLIC_WC_APP_TYPE = frontend

You must configure the following options:

NEXT_PUBLIC_WC_API_HOST
NEXT_PUBLIC_WC_CDN_PRODUCTS
NEXT_PUBLIC_WC_CDN_TEMP_PRODUCTS
  1. Configure NGINX:
sudo nano /etc/nginx/sites-available/default

Change the configuration as follows for the frontend (NGINX reverse proxy):

server {
    #listen 443 http2 ssl default_server;
    listen 80 default_server;
    server_name _;
    
    #ssl_certificate_key /etc/ssl/wexcommerce.key;
    #ssl_certificate /etc/ssl/wexcommerce.pem;

    access_log /var/log/nginx/wexcommerce.frontend.access.log;
    error_log /var/log/nginx/wexcommerce.frontend.error.log;

    location / {
      # reverse proxy for next server
      proxy_pass http://localhost:8001;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
    }

    location /cdn {
      alias /var/www/cdn;
    }
}

If you want to enable SSL, uncomment these lines:

#listen 443 http2 ssl default_server;
#ssl_certificate_key /etc/ssl/wexcommerce.key;
#ssl_certificate /etc/ssl/wexcommerce.pem;

Change the configuration as follows for the backend (NGINX reverse proxy):

server {
    #listen 3000 http2 ssl default_server;
    listen 3000 default_server;
    server_name _;

    #ssl_certificate_key /etc/ssl/wexcommerce.key;
    #ssl_certificate /etc/ssl/wexcommerce.pem;

    #error_page 497 301 =307 https://$host:$server_port$request_uri;

    access_log /var/log/nginx/wexcommerce.backend.access.log;
    error_log /var/log/nginx/wexcommerce.backend.error.log;

    location / {
      # reverse proxy for next server
      proxy_pass http://localhost:8002;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
    }
}

If you want to enable SSL, uncomment these lines:

#listen 3000 http2 ssl default_server;
#ssl_certificate_key /etc/ssl/wexcommerce.key;
#ssl_certificate /etc/ssl/wexcommerce.pem;
#error_page 497 301 =307 https://$host:$server_port$request_uri;

Then, check nginx configuration and start nginx service:

sudo nginx -t
sudo systemctl restart nginx.service
sudo systemctl status nginx.service
  1. enable firewall and open wexCommerce ports:
sudo ufw enable
sudo ufw allow 4004/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 3000/tcp
  1. Deploy wexCommerce:
wc-deploy all

wexCommerce backend is accessible on port 3000 and the frontend is accessible on port 80 or 443 if SSL is enabled.

  1. Create an admin user by navigating to hostname:3000/sign-up

  2. Open backend/pages/sign-up.js and uncomment this line to secure the backend:

if (process.env.NODE_ENV === 'production') return { notFound: true };
  1. Redeploy wexCommerce backend:
wc-deploy backend

You can change language and currency from settings page from the backend.