To advertise with us contact on Whatsapp: +923041280395 For guest post email at: [email protected]

Learn to Install Odoo 14 on Ubuntu 20.04 Linux

Learn to Install Odoo 14 on Ubuntu 20.04 Linux

Odoo is a popular open-source suite of business apps that help companies to manage and run their business. It includes a wide range of applications such as CRM, e-Commerce, website builder, billing, accounting, manufacturing, warehouse, project management, inventory, and much more, all seamlessly integrated.

Odoo can be installed in different ways, depending on the use case and available technologies. The easiest and quickest way to install Odoo is by using the official Odoo APT repositories.

Installing Odoo in a virtual environment, or deploying as a Docker container, gives you more control over the application and allows you to run multiple Odoo instances on the same system.

This article explains how to install and deploy Odoo 14 inside a Python virtual environment on Ubuntu 20.04. We’ll download Odoo from the official GitHub repository and use Nginx as a reverse proxy.

Prerequisites

  • You must be registered with Alibaba Cloud.
  • You must have added and verified your payment method.
  • If you are a new user, after payment method verification you can claim free $450 – $1300 credits. You can register new account and claim your free credits.
  • To setup up your ECS for the first time, you can refer to this tutorial or quick-start guide.
  • Domain registration is recommended for setting up FQDN hostname of your server. But if you are willing to use IP address directly, you may skip this.
  • If you have registered domain with any 3rd party, you may transfer into Alibaba Cloud.
  • If you are using the domain name, remember to point your domain name to IP address of your server.
  • You should set up your server’s hostname.
  • Access to VNC console in your Alibaba Cloud or SSH client installed in your PC.
  • Login as root user and create a user with sudo privileges.

Install Git

In the first step, we will be installing Git using the command below.

$ sudo apt install git

Install Node.js

Now we will install node js.

$ sudo apt install node-less

Install Pip

To install pip execute the command below.

$ sudo apt install python3-pip build-essential wget python3-dev python3-venv python3-wheel libxslt-dev libzip-dev libldap2-dev libsasl2-dev python3-setuptools libjpeg-dev zlib1g-dev libpq-dev

Creating a System User

Running Odoo under the root user is not allowed, as it is a security risk. We’ll create a new system user and group with home directory /opt/odoo14 that will run the Odoo service. To do so, enter the following command:

$ sudo useradd -m -d /opt/odoo14 -U -r -s /bin/bash odoo14

You can name the user anything you want, as long you create a PostgreSQL user with the same name.

Installing and Configuring PostgreSQL

Odoo uses PostgreSQL as the database back-end. PostgreSQL is included in the standard Ubuntu repositories. To install it, run:

$ sudo apt install postgresql

When the installation is completed, create a PostgreSQL user with the same name as the previously created system user. In this example, that is odoo14:

$ sudo su - postgres -c "createuser -s odoo14"

Installing wkhtmltopdf

wkhtmltopdf is a set of open-source command-line tools for rendering HTML pages into PDF and various image formats. To print PDF reports in Odoo, you’ll need to install the wkhtmltox package. The recommended version for Odoo is version 0.12.5, which can be download from Github:

$ sudo wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb

Once the file is downloaded, install it by typing:

$ sudo apt install ./wkhtmltox_0.12.6-1.bionic_amd64.deb

Installing and Configuring Odoo 14

We’ll install Odoo from the source inside an isolated Python virtual environment.

First, change to user “odoo14”:

sudo su - odoo14

Clone the Odoo 14 source code from GitHub:

$ git clone https://www.github.com/odoo/odoo --depth 1 --branch 14.0 /opt/odoo14/odoo

Create a new Python virtual environment for Odoo:

$ cd /opt/odoo14
$ python3 -m venv odoo-venv

Activate the virtual environment:

$ source odoo-venv/bin/activate

Install all required Python modules with pip3:

$ pip3 install wheel
$ pip3 install -r odoo/requirements.txt

Once done, deactivate the environment by typing:

$ deactivate

Create a new directory that will contain the 3rd party addons:

$ mkdir /opt/odoo14/odoo-custom-addons

Later, we’ll add this directory to the addons_path parameter. This parameter defines a list of directories where Odoo searches for modules.

Switch back to your sudo user:

$ exit

Create a configuration file with the following content:

$ sudo nano /etc/odoo14.conf

Now edit /etc/odoo14.conf

[options]
; This is the password that allows database operations:
admin_passwd = my_admin_passwd
db_host = False
db_port = False
db_user = odoo14
db_password = False
addons_path = /opt/odoo14/odoo/addons,/opt/odoo14/odoo-custom-addons

Creating Systemd Unit File

Open your text editor and create a service unit file called odoo14.service with the following content:

$ sudo nano /etc/systemd/system/odoo14.service

Now you need to edit /etc/systemd/system/odoo14.service using nano editor or vim.

[Unit]
Description=Odoo14
Requires=postgresql.service
After=network.target postgresql.service

[Service]
Type=simple
SyslogIdentifier=odoo14
PermissionsStartOnly=true
User=odoo14
Group=odoo14
ExecStart=/opt/odoo14/odoo-venv/bin/python3 /opt/odoo14/odoo/odoo-bin -c /etc/odoo14.conf
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target

Notify systemd that a new unit file exists:

$ sudo systemctl daemon-reload

Start the Odoo service and enabled it to start on boot by running:

$ sudo systemctl enable --now odoo14

Verify the service status:

$ sudo systemctl status odoo14

Testing the Installation

Open your browser and type: http://<your_domain_or_IP_address>:8069

Assuming the installation is successful, a screen similar to the following will appear:

Configuring Nginx as SSL Termination Proxy

The default Odoo web server is serving traffic over HTTP. To make the Odoo deployment more secure, we will set Nginx as an SSL termination proxy that will serve the traffic over HTTPS.

SSL termination proxy is a proxy server that handles the SSL encryption/decryption. This means that the termination proxy (Nginx) will process and decrypt incoming TLS connections (HTTPS), and pass on the unencrypted requests to the internal service (Odoo). The traffic between Nginx and Odoo will not be encrypted (HTTP).

Using a reverse proxy gives you a lot of benefits such as Load Balancing, SSL Termination, Caching, Compression, Serving Static Content, and more.

Ensure that you have met the following prerequisites before continuing with this section:

  • Domain name pointing to your public server IP. We’ll use example.com.
  • Nginx installed .
  • SSL certificate for your domain. You can install a free Let’s Encrypt SSL certificate .

Open your text editor and create/edit the domain server block:

$ sudo nano /etc/nginx/sites-enabled/example.com

The following configuration sets up SSL Termination, HTTP to HTTPS redirection , WWW to non-WWW redirection, cache the static files, and enable GZip compression.

Now edit /etc/nginx/sites-enabled/example.com

# Odoo servers
upstream odoo {
server 127.0.0.1:8069;
}

upstream odoochat {
server 127.0.0.1:8072;
}

# HTTP -> HTTPS
server {
listen 80;
server_name www.example.com example.com;

include snippets/letsencrypt.conf;
return 301 https://example.com$request_uri;
}

# WWW -> NON WWW
server {
listen 443 ssl http2;
server_name www.example.com;

ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
include snippets/ssl.conf;
include snippets/letsencrypt.conf;

return 301 https://example.com$request_uri;
}

server {
listen 443 ssl http2;
server_name example.com;

proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;

# Proxy headers
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;

# SSL parameters
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
include snippets/ssl.conf;
include snippets/letsencrypt.conf;

# log files
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;

# Handle longpoll requests
location /longpolling {
proxy_pass http://odoochat;
}

# Handle / requests
location / {
proxy_redirect off;
proxy_pass http://odoo;
}

# Cache static files
location ~* /web/static/ {
proxy_cache_valid 200 90m;
proxy_buffering on;
expires 864000;
proxy_pass http://odoo;
}

# Gzip
gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
gzip on;
}

Once you’re done, restart the Nginx service :

$ sudo systemctl restart nginx

Next, we need to tell Odoo to use the proxy. To do so, open the configuration file and add the following line:

Now edit /etc/odoo14.conf

proxy_mode = True

Restart the Odoo service for the changes to take effect:

sudo systemctl restart odoo14

At this point, the reverse proxy is configured, and you can access your Odoo instance at https://example.com.

Changing the Binding Interface

This step is optional, but it is a good security practice.

By default, the Odoo server listens to port 8069 on all interfaces. To disable direct access to the Odoo instance, you can either block the port 8069 for all public interfaces or force Odoo to listen only on the local interface.

We’ll configure Odoo to listen only on 127.0.0.1. Open the configuration add the following two lines at the end of the file:

Update /etc/odoo14.conf

xmlrpc_interface = 127.0.0.1
netrpc_interface = 127.0.0.1

Save the configuration file and restart the Odoo server for the changes to take effect:

$ sudo systemctl restart odoo14

Enabling Multiprocessing

By default, Odoo is working in multithreading mode. For production deployments, it is recommended to change to the multiprocessing server as it increases stability and makes better usage of the system resources.

To enable multiprocessing, you need to edit the Odoo configuration and set a non-zero number of worker processes. The number of workers is calculated based on the number of CPU cores in the system and the available RAM memory.

According to the official Odoo documentation , to calculate the workers’ number and required RAM memory size, you can use the following formulas and assumptions:

Worker number calculation

  • Theoretical maximal number of worker = (system_cpus * 2) + 1
  • 1 worker can serve ~= 6 concurrent users
  • Cron workers also require CPU

RAM memory size calculation

  • We will consider that 20% of all requests are heavy requests, and 80% are lighter ones. Heavy requests are using around 1 GB of RAM while the lighter ones are using around 150 MB of RAM
  • Needed RAM = number_of_workers * ( (light_worker_ratio * light_worker_ram_estimation) + (heavy_worker_ratio * heavy_worker_ram_estimation) )

If you do not know how many CPUs you have on your system, use the following grep command:

$ grep -c ^processor /proc/cpuinfo

Let’s say you have a system with 4 CPU cores, 8 GB of RAM memory, and 30 concurrent Odoo users.

  • 30 users / 6 = **5** (5 is theoretical number of workers needed )
  • (4 * 2) + 1 = **9** ( 9 is the theoretical maximum number of workers)

Based on the calculation above, you can use 5 workers + 1 worker for the cron worker that is a total of 6 workers.

Calculate the RAM memory consumption based on the number of workers:

  • RAM = 6 * ((0.8*150) + (0.2*1024)) ~= 2 GB of RAM

The calculation shows that the Odoo installation will need around 2GB of RAM.

To switch to multiprocessing mode, open the configuration file /etc/odoo14.conf and append the calculated values:

limit_memory_hard = 2684354560
limit_memory_soft = 2147483648
limit_request = 8192
limit_time_cpu = 600
limit_time_real = 1200
max_cron_threads = 1
workers = 5

Restart the Odoo service for the changes to take effect:

$ sudo systemctl restart odoo14

The rest of the system resources will be used by other services that run on this system. In this guide, we installed Odoo along with PostgreSQL and Nginx on the same server. Depending on your set up you may also have other services running on your server.

Conclusion

This article walked you through the installation of Odoo 14 on Ubuntu 20.04 in a Python virtual environment using Nginx as a reverse proxy. We’ve also shown you how to enable multiprocessing and optimize Odoo for a production environment.

Leave a Reply

Your email address will not be published.