Installing Odoo 18 on Ubuntu 24.04 and Deploying it using Nginx

How to Install Odoo 18 Community Edition on Ubuntu 24.04 and Deploying it Using Nginx with LetsEncrypt SSL
November 16, 2024 by
Installing Odoo 18 on Ubuntu 24.04 and Deploying it using Nginx
Hamed Mohammadi
| No comments yet

Ready to launch your Odoo 18 empire? This guide walks you through the steps of installing Odoo 18 Community Edition on Ubuntu 24.04, setting up PostgreSQL, and configuring Nginx as a reverse proxy. We'll also show you how to secure your Odoo instance with a free SSL certificate from Let's Encrypt.


Create a Dedicated System User for Odoo


Running Odoo as the root user is a major security risk. To protect your system, we'll create a dedicated system user and group. This user will have limited privileges, enhancing the security of your Odoo installation.

Execute the following command in your terminal to create a new user named odoo with a home directory of /opt/odoo:


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


This command will create the odoo user and group, ensuring that the Odoo service runs under a restricted account.


Installing Essential Tools and Dependency Packages


To ensure a smooth Odoo installation, we'll first install a few essential tools and dependencies. The first step is to install Git , Pip , Node.js , and development Odoo dependencies:


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



Additional Requirement for Right-to-Left Languages


If you plan to support right-to-left languages like Arabic, Persian, or Hebrew, you'll need to install the rtlcss package:


First install nodejs and npm with a package manager.


$ sudo apt install npm


And then install rtlcss using npm:


$ sudo npm install -g rtlcss


With these tools in place, we're ready to proceed with the Odoo installation.


Install PostgreSQL


Odoo relies on PostgreSQL as its robust database backend.. PostgreSQL is included in the standard Ubuntu repositories. The installation is simple:


$ sudo apt install postgresql



We'll create a PostgreSQL user named odoo to securely manage the Odoo database:


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




Install Wkhtmtopdf


wkhtmltopdf is not installed through pip and must be installed manually in version 0.12.6 for it to support headers and footers.

There is no wkhtmltopdf deb package for Ubuntu 24.04 Noble yet, but I tested installing the package for Jammy and it works fiine.


Download Wkhtmltopdf package:


​wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-3/wkhtmltox_0.12.6.1-3.jammy_amd64.deb



Install it using dpk:


$ sudo dpkg -i ./wkhtmltox_0.12.6.1-3.jammy_amd64.deb


If you encountered any dependency problems run: sudo apt --fix-broken install


Installing and Configuring Odoo 18


We’ll create a virtual environment for Odoo install Odoo from the source. We clone the Odoo 18 code from GitHub using git. All work is done by odoo system user.

First, change to user “odoo”:


$ sudo su - odoo


Then clone the Odoo 18 source code from GitHub:


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


Notice we have used depth to 1 to reduce download size and also ensure to get 18.0 branch. 

Create a new Python virtual environment for Odoo:


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


Activate the virtual environment:


$ source odoo-venv/bin/activate


All Python Odoo dependencies are specified in the requirements.txt file. We can install all required Python modules with pip3:


(odoo-venv) $ pip3 install wheel
(odoo-venv) $ pip3 install -r odoo/requirements.txt



It is important that if you encounter any compilation error during the installation, retry and make sure all required dependencies listed in the Installing Prerequisites section are installed.


Once done, deactivate the environment by typing:


(odoo-venv) $ deactivate



Odoo has a large number of additional modules on Odoo App Store. We’ll create a new directory  for the 3rd party addons:


$ mkdir /opt/odoo/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


Creating Configuration File for Odoo Instance



Create a configuration file /etc/odoo.conf:

$ sudo nano /etc/odoo.conf


And add these lines to it and save the file:


[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/odoo/addons,/opt/odoo/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 odoo.service with the following content:


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



Add change its content to:


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

[Service]
Type=simple
SyslogIdentifier=odoo
PermissionsStartOnly=true
User=odoo
Group=odoo
ExecStart=/opt/odoo/odoo-venv/bin/python3 /opt/odoo/odoo/odoo-bin -c /etc/odoo.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 odoo



Verify that the service is up and running:


$ sudo systemctl status odoo



The output should look something like below, showing that the Odoo service is active and running:


● odoo.service - Odoo
     Loaded: loaded (/etc/systemd/system/odoo.service; enabled; preset: enabled)
     Active: active (running) since Sat 2024-11-16 06:25:44 UTC; 27s ago


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


$ sudo journalctl -u odoo


You can test your odoo installation by entering your ip adress and port 8069:

your_ip_address:8069

odoo database selector


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 https://example.com/.

Nginx installed.

SSL certificate for your domain. You can install a free Let’s Encrypt SSL certificate .


Install Nginx


Nginx is available in the default Ubuntu repositories. To install it run the following commands:


$ sudo apt install nginx



Once the installation is completed, the Nginx service will start automatically. You can verify it by running:


$ sudo systemctl status nginx



The output will look something like this:


● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
     Active: active (running) since Sat 2024-11-16 06:51:47 UTC; 16s ago


If you are running ufw behind ufw firewall allow Nginx connections:


$ sudo ufw allow 'Nginx Full'




Obtain Free LetsEncrypt Certificate


Use this guide to obtain a free LetsEncrypt certificate for your website using Certbot: 

Obtaining an SSL Certificate for Your Site for Nginx on Ubuntu


After obtaining your ssl certificate open your text editor and edit the domain server block:


$ 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, cache the static files, and enable GZip compression. We have also increased client_max_body_size from default 2 M value to 20 M, so we won't get Connection lost error when saving settings in Odoo.


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

upstream odoochat {
 server 127.0.0.1:8072;
}

map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

# 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;
    
    # Increase client_max_body_size to your required ammount
    client_max_body_size 20M;

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

    # Redirect websocket requests to odoo gevent port
    location /websocket {
    proxy_pass http://odoochat;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header X-Forwarded-Host $http_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;
  }

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

    # Redirect requests to odoo backend server
    location / {
	    # Add Headers for odoo proxy mode
	    proxy_set_header X-Forwarded-Host $http_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;
	    proxy_redirect off;
	    proxy_pass http://odoo;

	    # Enable HSTS
	    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
	    # requires nginx 1.19.8
	    #proxy_cookie_flags session_id samesite=lax secure;
    }

    # 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 https://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’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 /etc/odoo.conf and add the following line:


proxy_mode = True


And then restart odoo service:


$ sudo systemctl restart odoo



And after this, 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 https://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 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 file /etc/odoo.conf add the following two lines at the end of the file:


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 odoo



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. It is also critical for avoiding Connection lost error.


To enable multiprocessing, you need to edit the Odoo configuration /etc/odoo.conf 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) )


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/odoo.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 odoo



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.


Running Multiple Odoo Instances on a Single Server


Want to host multiple Odoo instances on a single server? No problem! Odoo allows you to easily configure multiple databases, each serving a different domain. To enable this feature, simply add the dbfilter option to your Odoo configuration file (/etc/odoo.conf):


dbfilter = ^%d$


This configuration allows Odoo to recognize multiple databases based on their names.After making this change, restart the Odoo service to apply the new configuration:


$ sudo systemctl restart odoo



With this configuration, you can create multiple Odoo databases, each with its own domain and data, all running on the same server.


Conclusion


This article explained how to install and configure Odoo 18 on Ubuntu 24.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.

You can also consider securing your server by installing and configuring UFW firewall. Also consider fine tuning your PostgreSQL for your needs.

odoo 18 apps

in Odoo
Installing Odoo 18 on Ubuntu 24.04 and Deploying it using Nginx
Hamed Mohammadi November 16, 2024
Share this post
Tags
Archive

Please visit our blog at:

https://zehabsd.com/blog

A platform for Flash Stories:

https://readflashy.com

A platform for Persian Literature Lovers:

https://sarayesokhan.com

Sign in to leave a comment