Odoo is the most popular all-in-one business software in the world packed up a range of business applications, including CRM, website ,e-Commerce, billing, accounting, manufacturing, warehouse, project management, inventory and much more, all seamlessly integrated.
There are several ways to install Odoo depending on the required use case. This guide covers the steps necessary for installing and configuring Odoo for production using Git source and Python virtualenv on a Ubuntu 18.04 system.

Before you begin

Update the system to the latest packages:
sudo apt update && sudo apt upgrade
Copy
Install git, pip and the tools and libraries required to build Odoo dependencies:
sudo apt install git python3-pip build-essential wget python3-dev libxslt-dev libzip-dev libldap2-dev libsasl2-dev python3-setuptools
Copy

Create Odoo user

Create a new system user and group with home directory /opt/odoo that will run the Odoo service.
useradd -m -d /opt/odoo -U -r -s /bin/bash odoo
Copy
You can name the user whatever you like, just make sure you create a postgres user with the same name.

Install and configure PostgreSQL

Install the Postgres package from the Ubuntu’s default repositories:
sudo apt-get install postgresql
Copy
Once the installation is completed create a postgres user with the same name as the previously created system user, in our case odoo:
sudo su - postgres -c "createuser -s odoo"
Copy

Install and configure Odoo

We will install odoo from the GitHub repository so we can have more control over versions and updates. We will also use virtualenv which is a tool to create isolated Python environments.
Before starting with the installation process, make sure you switch to odoo user.
sudo su - odoo
Copy
To confirm that you are logged-in as odoo user you can use the following command:
whoami
Copy
Now we can start with the installation process, first clone the odoo from the GitHub repository:
git clone https://www.github.com/odoo/odoo --depth 1 --branch 11.0 /opt/odoo/odoo11
Copy
  • If you want to install a different Odoo version just change the version number after the --branch switch.
  • You can name the directory as you like, for example instead odoo11 you can use the name of your domain.
pip is a tool for installing and managing Python packages, which we will use to install all required Python modules, install it with:
pip3 install virtualenv
Copy
To create a new virtual environment for our Odoo 11 installation run:
cd /opt/odoo
virtualenv odoo11-venv
Copy
Using base prefix '/usr'
New python executable in /opt/odoo/odoo11-venv/bin/python3
Also creating executable in /opt/odoo/odoo11-venv/bin/python
Installing setuptools, pip, wheel...done.
Copy
activate the environment:
source odoo11-venv/bin/activate
Copy
and install all required Python modules:
pip3 install -r odoo11/requirements.txt
Copy
If you encounter any compilation errors during the installation, make sure that you installed all of the required dependencies listed in the Before you begin section.
Once the installation is completed deactivate the environment and switch back to your sudo user using the following commands:
deactivate
exit
Copy
If you plan to install custom modules it is best to install those modules in a separate directory. To create a new directory for our custom modules run:
sudo mkdir /opt/odoo/odoo11-custom-addons
sudo chown odoo: /opt/odoo/odoo11-custom-addons
Copy
Next, we need to create a configuration file, we can either create a new one from scratch or copy the included configuration file:
sudo cp /opt/odoo/odoo11/debian/odoo.conf /etc/odoo11.conf
Copy
Open the file and edit it as follows:
/etc/odoo11.conf
[options]
; This is the password that allows database operations:
admin_passwd = my_admin_passwd
db_host = False
db_port = False
db_user = odoo
db_password = False
addons_path = /opt/odoo/odoo11/addons
; If you are using custom modules
; addons_path = /opt/odoo/odoo11/addons,/opt/odoo/odoo11-custom-addons
Copy
Do not forget to change the my_admin_passwd to something more secure and adjust the addons_path if you’re using custom modules.
Advertisement

Create a systemd unit file

To run odoo as a service we will create a odoo11.service unit file in the /etc/systemd/system/ directory with the following contents:
/etc/systemd/system/odoo11.service
[Unit]
Description=Odoo11
Requires=postgresql.service
After=network.target postgresql.service

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

[Install]
WantedBy=multi-user.target
Copy
Notify systemd that we created a new unit file and start the Odoo service by executing:
sudo systemctl daemon-reload
sudo systemctl start odoo11
Copy
You can check the service status with the the following command:
sudo systemctl status odoo11
Copy
● odoo11.service - Odoo11
   Loaded: loaded (/etc/systemd/system/odoo11.service; disabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-05-03 21:23:08 UTC; 3s ago
 Main PID: 18351 (python3)
    Tasks: 4 (limit: 507)
   CGroup: /system.slice/odoo11.service
           └─18351 /opt/odoo/odoo11-venv/bin/python3 /opt/odoo/odoo11/odoo-bin -c /etc/odoo11.conf
Copy
and if there are no errors you can enable the Odoo service to be automatically started at boot time:
sudo systemctl enable odoo11
Copy
If you want to see the messages logged by the Odoo service you can use the command below:
sudo journalctl -u odoo11
Copy

Test the Installation

Open your browser and type: http://:8069
Assuming that installation is successful, a screen similar to the following will appear:

Configure Nginx as a SSL termination proxy

If you want to use Nginx as a SSL termination proxy make sure that you have meet the following prerequisites:
  • You have a domain name pointing to your public server IP. In this tutorial we will use example.com.
  • You have Nginx installed by following this introductions.
  • You have a SSL certificate installed for your domain. You can install a free Let’s Encrypt SSL certificate by following this introductions .
The default Odoo web server is serving traffic over HTTP. To make our Odoo deployment most secure we will configure Nginx as a SSL termination proxy which will serve the traffic over HTTPS.
SSL termination proxy is a proxy server which handles the SSL encryption/decryption. This means that our termination proxy (Nginx) will handle and decrypt incoming TLS connections (HTTPS), and it will pass on the unencrypted requests to our internal service (Odoo) so the traffic between Nginx and Odoo will not be encrypted (HTTP).
We need to tell Odoo that we will use a proxy, open the configuration file and add the following line:
/etc/odoo11.conf
proxy_mode = True
Copy
Restart the Odoo service for the changes to take effect:
sudo systemctl restart odoo11
Copy
Using Nginx as a proxy give us several benefits. In this example we will configure SSL Termination, HTTP to HTTPS redirection, WWW to non-WWW redirection, cache the static files and enable GZip compression.
/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;

    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;

    # 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;
}
Copy
Don’t forget to replace example.com with your Odoo domain and set the correct path to the SSL certificate files. The snippets used in this configuration are created in this guide .
Once you are done, restart the Nginx service with:
sudo systemctl restart nginx
Copy

Change the binding interface

This step is optional, but it is a good security practice. By default, Odoo server listens to port 8069 on all interfaces, so if you want to disable direct access to your Odoo instance you can either block the port 8069 for all public interfaces or force Odoo to listen only on the local interface.
In this guide we will force Odoo to listen only on 127.0.0.1, open the Odoo configuration add the following two lines at the end of the file:
/etc/odoo11.conf
xmlrpc_interface = 127.0.0.1
netrpc_interface = 127.0.0.1
Copy
Save the configuration file and restart the Odoo server for the changes to take effect:
sudo systemctl restart odoo
Copy

Enable multiprocessing

By default, Odoo is working in multithreading mode. For production deployments, it is recommended to switch to the multiprocessing server as it increases stability, and make better usage of the system resources. In order to enable multiprocessing we need to edit the Odoo configuration and set a non-zero number of worker processes.
Multiprocessing mode is only available on Unix-based systems it is available on Windows systems
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](“https://www.odoo.com/documentation/11.0/setup/deploy.html") to calculate the workers number and required RAM memory size we will 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 requires CPU
RAM memory size calculation
  • We will consider that 20% of all requests are heavy requests, while 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 you can use the following command:
grep -c ^processor /proc/cpuinfo
Copy
Let’s say we 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 we can use 5 workers + 1 worker for the cron worker which is total of 6 workers. Let’s check if the RAM memory consumption based on the number of the workers.
  • RAM = 6 * ((0.8*150) + (0.2*1024)) ~= 2 GB of RAM
The calculation above show us that our Odoo installation will need around 2GB of RAM.
To switch to multiprocessing mode, open the configuration file and append the following lines:
/etc/odoo11.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
Copy
Restart the Odoo service for the changes to take effect:
sudo systemctl restart odoo11
Copy
The rest of the system resources will be used by other services that run on our machine. In this guide we installed Odoo along with PostgreSQL and Nginx on a same server and depending on your setup you may also have other services running on your server.