Installing Odoo 16 ERP on Ubuntu 22.04

Odoo, previously named OpenERP, is a powerful, self-hosted suite of over 10,000 open-source applications tailored for various business needs. As a comprehensive ERP solution, Odoo offers functionalities such as customer relationship management (CRM), sales pipeline management, project management, manufacturing, invoicing, accounting, eCommerce, and more.

With its 30 core modules and over 4500 community modules, Odoo stands as one of the most complete ERP solutions available, seamlessly integrating into multiple types of businesses.

In this guide, we will detail how to install the latest stable version of Odoo 16 on an Ubuntu 22.04 server. This includes setting up a PostgreSQL database tailored for Odoo and configuring Nginx to act as a reverse proxy.

Prerequisites

Before starting, ensure you have the following:

  • An Ubuntu 22.04 server with the hostname ‘odoo-server‘.
  • A non-root user with sudo privileges or root user access.
  • A domain name pointing to your server’s IP address, which is necessary for production installations.

Installing Dependencies

First, update your package index:

sudo apt update

Install package dependencies for Odoo:

sudo apt install git wget python3 build-essential libzip-dev python3-dev libxslt1-dev python3-pip libldap2-dev python3-wheel libsasl2-dev python3-venv python3-setuptools node-less libjpeg-dev xfonts-75dpi xfonts-base libxrender1 libpq-dev libffi-dev fontconfig

install dependencies

Installing Node.js

Node.js is crucial for generating static files for Odoo applications. Install Node.js 16 from the Nodesource repository:

sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

setup nodesource

Next, install Node.js:

sudo apt install nodejs

install nodejs

Install ‘rtlcss’, necessary for right-to-left language support:

sudo npm install -g rtlcss

Installing Wkhtmltopdf

Wkhtmltopdf allows Odoo to convert HTML to PDF and other formats. Download and install it:

cd /tmp
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
sudo dpkg -i wkhtmltox_0.12.6.1-2.jammy_amd64.deb

install wkhtmltopdf

If an error occurs, fix missing dependencies:

sudo apt install -f

Installing PostgreSQL Database Server

Install PostgreSQL, which Odoo uses by default:

sudo apt install postgresql

install postgresql

Verify PostgreSQL is running:

sudo systemctl is-enabled postgresql
sudo systemctl status postgresql

check postgresql service

Create a PostgreSQL role for Odoo:

su - postgres
createuser -sdP odoo

create postgresql role

Configure role authentication in /etc/postgresql/14/main/pg_hba.conf:

host    all   odoo    127.0.0.1/32    scram-sha-256

Restart PostgreSQL to apply changes:

sudo systemctl restart postgresql

Verify the new role:

su - postgres
psql -h 127.0.0.1 -U odoo -d postgres
\conninfo

check postgresql role

Downloading Odoo 16

Create a new user for Odoo:

sudo adduser --system --group --home=/opt/odoo --shell=/bin/bash odoo

Download Odoo version 16:

cd /opt/odoo
git clone https://github.com/odoo/odoo.git --depth 1 --branch 16.0 --single-branch odoo-server

download odoo

Adjust permissions:

sudo chown -R odoo:odoo /opt/odoo/odoo-server

Installing Python Dependencies for Odoo

Set up a Python virtual environment:

cd /opt/odoo/odoo-server
python3 -m venv venv
source venv/bin/activate

setup python venv

Install dependencies:

pip3 install wheel
pip3 install -r requirements.txt

install dependnecies

Exit the virtual environment:

deactivate

Creating Odoo Configuration

Create the Odoo configuration file:

sudo nano /etc/odoo.conf

Use the following configuration, updating with your credentials:

[options]
; This is the password that allows database operations:
admin_passwd = adminpassodoo
db_host = 127.0.0.1
db_port = 5432
db_user = odoo
db_password = odoopass
addons_path = /opt/odoo/odoo-server/addons
xmlrpc_port = 8069
logfile = /var/log/odoo/odoo-server.log
log_level  = debug

Adjust file permissions:

sudo chown odoo:odoo /etc/odoo.conf

Create and set permissions for the log directory:

sudo mkdir /var/log/odoo
sudo chown odoo:odoo /var/log/odoo 
sudo chmod 755 /var/log/odoo

create odoo configuration

Running Odoo as a Systemd Service

Create a systemd service file:

sudo nano /lib/systemd/system/odoo-server.service

Insert the following configuration:

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

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

[Install]
WantedBy=multi-user.target

Reload systemd manager and enable Odoo service:

sudo systemctl daemon-reload
sudo systemctl start odoo-server
sudo systemctl enable odoo-server

setup odoo service

Verify the service:

sudo systemctl status odoo-server

check odoo service

Running Odoo with Nginx Reverse Proxy

Configure Odoo for reverse proxy:

sudo nano /etc/odoo.conf

Add to the file:

xmlrpc_interface = 127.0.0.1
proxy_mode = True
sudo systemctl restart odoo-server

configure odoo

Install Nginx:

sudo apt install nginx

install nginx

Configure Nginx as reverse proxy:

sudo nano /etc/nginx/sites-available/odoo.conf

Insert the following configuration, adjusting domain and certificate paths:

#odoo server
upstream odoo {
 server 127.0.0.1:8069;
}
upstream odoochat {
 server 127.0.0.1:8072;
}

# http -> https
server {
  listen 80;
  server_name odoo.hwdomain.io;
  rewrite ^(.*) https://$host$1 permanent;
}

server {
 listen 443 ssl http2;
 server_name odoo.hwdomain.io;
 proxy_read_timeout 720s;
 proxy_connect_timeout 720s;
 proxy_send_timeout 720s;

 # Add Headers for odoo proxy mode
 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/odoo.hwdomain.io/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/odoo.hwdomain.io/privkey.pem;
 ssl_session_timeout 1d;
 ssl_session_cache shared:MozSSL:10m;  # about 40000 sessions
 ssl_session_tickets off;
 ssl_protocols TLSv1.2 TLSv1.3;
 ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
 ssl_prefer_server_ciphers off;

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

 # Redirect longpoll requests to odoo longpolling port
 location /longpolling {
 proxy_pass http://odoochat;
 }

 # Redirect requests to odoo backend server
 location / {
  proxy_redirect off;
  proxy_pass http://odoo;
 }

 # common gzip
 gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
 gzip on;
}

Enable configuration and restart Nginx:

sudo ln -s /etc/nginx/sites-available/odoo.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

setup nginx reverse proxy

Setting up UFW Firewall

Enable the firewall to secure your Odoo installation:

sudo ufw allow "OpenSSH"
sudo ufw enable

setup ufw

Allow Nginx Full profile:

sudo ufw allow "Nginx Full"

Check status:

sudo ufw status

setup ufw

Migrating Database and Installing Odoo 16

Visit the domain name in your web browser (e.g., https://odoo.hwdomain.io/). Create your database and admin user:

Use the ‘admin_passwd’ from your configuration file. Input your database name, admin user, and password. Optionally, add demo data:

odoo migrate database

Log in with the admin account:

login odoo

Welcome to your Odoo dashboard!

odoo dashboard

Conclusion

Congratulations! You’ve successfully installed Odoo ERP on an Ubuntu 22.04 server with PostgreSQL and Nginx as a reverse proxy. Your installation is now secured and ready for business applications. Consider adding plugins or modules to extend functionality as needed.

Frequently Asked Questions

1. What is Odoo?
Odoo is a suite of open-source business applications that cover various business needs, including CRM, eCommerce, accounting, inventory, point of sale, and project management.
2. Can I use a different OS version?
This guide is specifically tailored for Ubuntu 22.04. While Odoo can be installed on other versions and distributions, adjustments in commands and package management may be necessary.
3. Is PostgreSQL the only database supported by Odoo?
No, Odoo also supports other databases like MySQL and SQLite, although PostgreSQL is the most common choice due to its robustness and Odoo’s extensive support for it.
4. How can I secure my Odoo installation?
Enable UFW firewall rules, configure Nginx reverse proxy with SSL, and regularly update your system and Odoo to protect against vulnerabilities.
5. Can I install additional modules?
Yes, Odoo’s modular architecture allows you to install additional community and enterprise modules to expand its functionality.