Odoo is a widely adopted open-source suite of business applications designed to assist companies in effectively managing and operating their businesses. This comprehensive suite encompasses a diverse range of applications, including CRM, e-Commerce, website building, billing, accounting, manufacturing, warehouse management, project management, inventory, and more. The seamless integration of these applications allows for streamlined operations and enhanced efficiency within the organization.

There are multiple installation methods available for Odoo, depending on your specific use case and available technologies. The most convenient and expedient approach is to utilize the official Odoo APT repositories for installation.

For greater control over the application and the ability to run multiple Odoo instances on a single system, you have the option to install Odoo within a virtual environment or deploy it as a Docker container.

In this article, we will guide you through the process of installing and deploying Odoo 15 within a Python virtual environment on Ubuntu 20.04. The installation involves downloading Odoo from the official GitHub repository, and we will configure Nginx as a reverse proxy to optimize the setup.

Installing Dependencies

The first step is to install Git , Pip , Node.js , and development [tools required to build]

sudo apt update
sudo apt install git python3-pip build-essential wget python3-dev python3-venv \
    python3-wheel libfreetype6-dev libxml2-dev libzip-dev libldap2-dev libsasl2-dev \
    python3-setuptools node-less libjpeg-dev zlib1g-dev libpq-dev \
    libxslt1-dev libldap2-dev libtiff5-dev libjpeg8-dev libopenjp2-7-dev \
    liblcms2-dev libwebp-dev libharfbuzz-dev libfribidi-dev libxcb1-dev

Creating a System User

Running Odoo with the root user presents significant security risks. To mitigate this, it is essential to create a new system user and group specifically for running the Odoo service. This user will have the home directory set to /opt/odoo15. To create the user and group, execute the provided command:

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

You have the flexibility to choose any desired name for the system user, as long as you create a corresponding PostgreSQL user with the same name. This alignment between the system user and PostgreSQL user ensures proper integration and functionality between Odoo and the underlying database.

Installing and Configuring PostgreSQL

Odoo relies on PostgreSQL as its database back-end, and fortunately, PostgreSQL is readily available in the standard Ubuntu repositories. The installation process is straightforward

sudo apt install postgresql

Once the service is installed, create a PostgreSQL user with the same name as the previously created system user. In this example, that is odoo15:

sudo su - postgres -c "createuser -s odoo15"

Installing wkhtmltopdf

wkhtmltopdf is a collection of open-source command-line tools designed for converting HTML pages into PDF and other image formats. In order to generate PDF reports within Odoo, it is necessary to install the wkhtmltox package.

The version of wkhtmltopdf available in the Ubuntu repositories lacks support for headers and footers. Therefore, it is advisable to install version 0.12.5, which is the recommended version for Odoo. To accomplish this, we will download and install the package from GitHub.

sudo wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb

Once the file is downloaded, install it by typing:

sudo apt install ./wkhtmltox_0.12.5-1.bionic_amd64.deb

Installing and Configuring Odoo 15

To install Odoo from the source within an isolated Python virtual environment, follow these steps:

Switch to the “odoo15” user

sudo su - odoo15

Clone the Odoo 15 source code from GitHub:

git clone https://www.github.com/odoo/odoo --depth 1 --branch 15.0 /opt/odoo15/odoo

Create a new Python virtual environment for Odoo:

cd /opt/odoo15
python3 -m venv odoo-venv

Activate the virtual environment

source odoo-venv/bin/activate
source odoo-venv/bin/activate

To install all the required Python modules for Odoo, specified in the requirements.txt file, you can use pip3. Here’s the command to accomplish this:

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

If you encounter any compilation error during the installation, make sure all required dependencies are listed in the Installing Prerequisites section is installed.

Once done, deactivate the environment by typing:

deactivate

To create a separate directory for third-party addons in Odoo

mkdir /opt/odoo15/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/odoo15.conf
[options]
; This is the password that allows database operations:
admin_passwd = my_admin_passwd
db_host = False
db_port = False
db_user = odoo15
db_password = False
addons_path = /opt/odoo15/odoo/addons,/opt/odoo15/odoo-custom-addons

Do not forget to change the my_admin_passwd to something more secure.

Creating Systemd Unit File

A unit file is a configuration ini-style file that holds information about a service.

Open your text editor and create a file named odoo15.service with the following content:

sudo nano /etc/systemd/system/odoo15.service
/etc/systemd/system/odoo15.service
[Unit]
Description=Odoo15
Requires=postgresql.service
After=network.target postgresql.service

[Service]
Type=simple
SyslogIdentifier=odoo15
PermissionsStartOnly=true
User=odoo15
Group=odoo15
ExecStart=/opt/odoo15/odoo-venv/bin/python3 /opt/odoo15/odoo/odoo-bin -c /etc/odoo15.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 enable it to start on boot by running:

sudo systemctl enable --now odoo15

Verify that the service is up and running:

sudo systemctl status odoo15

The output should resemble the following, indicating that the Odoo service is active and running:

● odoo15.service - Odoo15
     Loaded: loaded (/etc/systemd/system/odoo15.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-10-26 09:56:28 UTC; 28s ago
...

You can check the messages logged by the Odoo service using the command below:

sudo journalctl -u odoo15

Testing the Installation 

Open your preferred web browser and enter the following URL in the address bar: 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

To enhance the security of your Odoo deployment, it is recommended to set up Nginx as an SSL termination proxy, serving traffic over HTTPS instead of the default HTTP. This ensures that the SSL encryption/decryption is handled by Nginx, acting as the termination proxy.

An SSL termination proxy is responsible for decrypting incoming TLS connections (HTTPS) and forwarding the unencrypted requests to the internal service (Odoo). The communication between Nginx and Odoo will occur over HTTP without encryption.

Using Nginx as a reverse proxy offers various advantages, including load balancing, SSL termination, caching, compression, serving static content, and more.

Before proceeding with this section, ensure that you have met the following prerequisites:

  1. A domain name pointing to your public server IP address. In this example, we’ll use “example.com” as the domain.
  2. Nginx is installed on your system.
  3. You have obtained an SSL certificate for your domain. You can install a free Let’s Encrypt SSL certificate.

Open your preferred text editor and create or edit the domain server block configuration for Nginx.

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

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

/etc/nginx/sites-enabled/example.com.conf
# 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;
}

Don’t forget to replace example.com with your Odoo domain and set the correct path to the SSL certificate files.

After making changes to the Nginx configuration, you need to restart the Nginx service to apply the new configuration. To restart the Nginx service, use the following command:

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:

/etc/odoo15.conf
proxy_mode = True

Restart the Odoo service for the changes to take effect:

sudo systemctl restart odoo15

With the reverse proxy properly configured, you can now access your Odoo instance securely using the HTTPS protocol. Simply open your web browser and navigate to https://example.com, where example.com should be replaced with your own domain name or IP address.

Changing the Binding Interface

To enhance the security of your Odoo instance, you can choose to disable direct access to the Odoo server by blocking port 8069 for all public interfaces or by configuring Odoo to listen only on the local interface.

To configure Odoo to listen only on the local interface (127.0.0.1), follow these steps:

Open the Odoo configuration file using a text editor:

sudo nano /etc/odoo/odoo.conf

Scroll to the end of the file and add the following two lines:

; Limit Odoo to listen only on the local interface
xmlrpc_interface = 127.0.0.1

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

sudo systemctl restart odoo15

Enabling Multiprocessing 

To optimize the performance and stability of your Odoo deployment, it is recommended to switch from multithreading mode to the multiprocessing server. This change allows for better utilization of system resources and enhances overall system stability.

To enable multiprocessing, you will need to modify the Odoo configuration file and specify the number of worker processes. The number of workers is determined based on the number of CPU cores available in your system and the amount of RAM memory.

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

Worker Number Calculation:
Theoretical maximum number of workers = (system_cpus * 2) + 1
Approximately 1 worker can handle around 6 concurrent users
Cron workers also require CPU resources

RAM Memory Size Calculation:
Assuming that 20% of the requests are heavy requests, using around 1 GB of RAM, and 80% are lighter requests, using around 150 MB of RAM, the formula for calculating the required RAM is as follows:
Needed RAM = number_of_workers * ((light_worker_ratio * light_worker_ram_estimation) + (heavy_worker_ratio * heavy_worker_ram_estimation))

If you are unsure about the number of CPUs in your system, you can use the following grep command to find out:

grep -c ^processor /proc/cpuinfo

This command will provide the number of CPUs in your system, which you can use in the worker number calculation.

By adjusting the number of worker processes and allocating the appropriate amount of RAM, you can optimize the performance of your Odoo instance based on your system’s capabilities.

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

Based on the calculation, we can determine the number of workers needed and the maximum number of workers:

Number of workers needed: 30 users / 6 = 5 workers (rounded up)
Theoretical maximum number of workers: (4 * 2) + 1 = 9 workers

Considering the above calculations, you can use 5 workers for regular usage and allocate 1 worker for the cron jobs, resulting in a total of 6 workers.

Next, let’s calculate the RAM memory consumption based on the number of workers:

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

Based on this calculation, the Odoo installation will require approximately 2 GB of RAM.

To switch to the multiprocessing mode, open the configuration file and add the calculated values to the respective settings:

/etc/odoo15.conf
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 odoo15

The remaining system resources will be allocated to other services running on the same system. In this guide, we have installed Odoo, PostgreSQL, and Nginx on the server. It’s important to note that depending on your setup, you may have additional services running on your server, which will also utilize system resources.

Conclusion

In this article, we have provided a step-by-step guide on installing and configuring Odoo 15 on Ubuntu 20.04. We covered the installation process within a Python virtual environment and demonstrated the setup of Nginx as a reverse proxy. Additionally, we explored how to enable multiprocessing and optimize Odoo for optimal performance in a production environment. By following these instructions, you can successfully set up and optimize Odoo for your business needs.

Comments to: How to Install Odoo 15 on Ubuntu 20.04

    Your email address will not be published. Required fields are marked *