How to deploy Odoo on a digital ocean Droplet

Go to the digital ocean dashboard. Click on the “Create” button and select “Droplets“.

  • Select a region closest to the user that will use the services
  • Select a VPC (Virtual Private Cloud). It will increase efficiency
  • Choose an Image, in other words an operating system (I am using ubuntu version 22.04LTS x 64)
  • Choose size (I am using 2 GB / 2 Intel CPUs, 60 GB NVMe SSDs, 3 TB transfer which is 21$/month right of 13.04.2023). It is recommended to have at least two CPU for better concurrent users)
  • Choose Authentication Method (Use SSH Key for better security)
  • Open up your terminal and type “ssh-keygen” to generate a pair of ssh keys. (It is better to keep all your keys inside “~/.ssh/” directory or on windows inside “C:\Users\$username\.ssh”. Remove the “$username” with your current username. Also on windows you need to setup openssh services to generate ssh key pair.)
  • This will create two files with your provided name. 1. $your_key.pub and $your_key
  • On digital ocean click on “New SSH Key”
  • Copy the content inside $your_key.pub and paste it on the digital ocean “SSH key Content”
  • Give it a name of your choice
  • Then click on “Add SSH Key”
  • You can check mark “Add improved metrics monitoring and alerting (free)” (optional)
  • Give a relative hostname for your droplet
  • Select a digital ocean project that the droplet should live (you can keep the default one)
  • Click on “Create Droplet”

This will take some time and create your droplet.

Connecting to the droplet

If you have multiple ssh keys on your computer, you will need a config file to manage all the keys. Go to the .ssh folder where you have previously generated the ssh key pair and create a txt file named “config”. Open the file with a text editor and follow the below structure to manage the ssh keys

Host $your-preferred-name
    HostName "$your_droplet_public_ip"
    User root
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/$your_keyname

**Remove the “” and $ signs and use your value on that place

  • “Host” is the your preferred name for referring ssh key configuration.
  • “HostName” should be your droplet’s public ip which you can find out on digital ocean
  • “User” should be “root” as initially digital ocean creates the droplet with the root user.
  • “PreferredAuthentications” should be “publickey”
  • “IdentityFile” should be the path of the private key of your generated ssh key pair (the one without any extension).

Now open up a terminal and type the following command

C:\Users\$username>ssh $your-preferred-name
The authenticity of host '$your_droplet_public_ip($your_droplet_public_ip)' can't be established.
ECDSA key fingerprint is SHA256:O/NTQ7nkPLjCQsnRi6x59hREoN/Ow7NeUebcV7KgA+s.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '$your_droplet_public_ip' (ECDSA) to the list of known hosts.
Enter passphrase for key '~/.ssh/$your_keyname': #enter_the_passphrase
Welcome to Ubuntu 22.10 (GNU/Linux 5.19.0-23-generic x86_64)

Now you should be logged in as root to your digital ocean server from the terminal

Initial Server Setup

The root user is the administrative user in a Linux environment that has very broad privileges. Because of the heightened privileges of the root account, you are discouraged from using it on a regular basis. This is because the root account is able to make very destructive changes, even by accident. So we need to create a new account for regular uses which can have temporary root privileges when you need them.

Creating a new user

root@odoo-droplet:~# adduser ubuntu

You will be asked a few questions, starting with the account password.

Granting Administrative Privileges

root@odoo-droplet:~# usermod -aG sudo ubuntu

Now, when logged in as your regular user, you can type sudo before commands to run them with superuser privileges.

Setting Up a Basic Firewall

It is best practice to setup a firewall in any server. By default Ubuntu has UFW firewall. To setup the firewall we will do the following

root@odoo-droplet:~# ufw app list
Available applications:
  OpenSSH

We need to make sure that firewall allow ssh connection so that we can log back in next time. We can do that by

root@odoo-droplet:~# ufw allow OpenSSH
Rules updated
Rules updated (v6)

After that we need to enable the firewall and check its status

root@odoo-droplet:~# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
root@odoo-droplet:~# ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)

Enabling External Access for Your Regular User

Now that we have a regular user for daily use, we need to make sure we can SSH into the account directly.

Execute the following command

rsync --archive --chown=ubuntu:ubuntu ~/.ssh /home/ubuntu

**Important: Don’t use trailing slash after the path.

This command will copy the .ssh folder with the necessary permissions from the root user to the user named ubuntu.

Change the config file as follows.

Host $your-preferred-name
    HostName "$your_droplet_public_ip"
    User root
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/$your_keyname

Host $your-preferred-name-ubuntu
    HostName "$your_droplet_public_ip"
    User ubuntu
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/$your_keyname

**Remove the “” and $ signs and use your value on that place

Now, open up a new terminal session on your local machine and do the followings

C:\Users\$username>ssh $your-preferred-name-ubuntu
Enter passphrase for key '~/.ssh/$your_keyname': #enter_the_passphrase
Welcome to Ubuntu 22.10 (GNU/Linux 5.19.0-23-generic x86_64)

Installing odoo

Update and upgrade system packages

prodip@odoo-droplet:~$ sudo apt update && sudo apt upgrade

All of your packages should be upgraded now.

Install dependencies

sudo apt install python3-pip wget python3-dev python3-venv python3-wheel libldap2-dev libpq-dev libsasl2-dev

PostgreSQL installation

prodip@odoo-droplet:~$ sudo apt install postgresql

Create PostgreSQL user

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

Create a system user for that postgresql user

prodip@odoo-droplet:~$ sudo adduser odoodbuser

Install libssl1.1

Download and install wkhtmltox

Download Odoo

Now switch to to the system user that is created for the odoo project. In my case it is odoodbuser

prodip@odoo-droplet:~$ sudo su odoodbuser
odoodbuser@odoo-droplet:/home/prodip$ cd ~
odoodbuser@odoo-droplet:~$

We don’t need to download all the branches and all the commits of the odoo projects. Follow the below instruction to download odoo 16.0 branch and 1 death of commits

odoodbuser@odoo-droplet:~$ git clone https://github.com/odoo/odoo.git --depth=1 --branch=16.0

Create and activate virtual environment

odoodbuser@odoo-droplet:~$ python3 -m venv myodoo-venv
odoodbuser@odoo-droplet:~$ source myodoo-venv/bin/activate
(myodoo-venv) odoodbuser@odoo-droplet:~$

Install wheel

(myodoo-venv) odoodbuser@odoo-droplet:~$ pip list
Package    Version
---------- -------
pip        22.2
setuptools 59.6.0
(myodoo-venv) odoodbuser@odoo-droplet:~$ pip install wheel
Collecting wheel
  Downloading wheel-0.40.0-py3-none-any.whl (64 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.5/64.5 kB 5.6 MB/s eta 0:00:00
Installing collected packages: wheel
Successfully installed wheel-0.40.0
(myodoo-venv) odoodbuser@odoo-droplet:~$ pip list
Package    Version
---------- -------
pip        22.2
setuptools 59.6.0
wheel      0.40.0

Install python modules

(myodoo-venv) odoodbuser@odoo-droplet:~$ pip install -r odoo/requirements.txt

Make directory for custom addons

(myodoo-venv) odoodbuser@odoo-droplet:~$ mkdir custom-addons

Logout as Odoo user

(myodoo-venv) odoodbuser@odoo-droplet:~$ deactivate
odoodbuser@odoo-droplet:~$ exit
exit
prodip@odoo-droplet:~$

Create Odoo configuration file

prodip@odoo-droplet:~$ sudo nano /etc/odoo.conf

/etc/odoo.conf

[options]
admin_passwd = linuxhint
db_host = False
db_port = False
db_user = odoodbuser
db_password = False
xmlrpc_port = 8069
logfile = /var/log/odoo16/odoo.log
addons_path = /home/odoodbuser/odoo/addons,/home/odoodbuser/custom-addons

Make log directory

prodip@odoo-droplet:~$ sudo mkdir /var/log/odoo16

prodip@odoo-droplet:~$ sudo chown odoodbuser:odoodbuser /var/log/odoo16

Create Odoo15 service

In the next step, we will create a Odoo systemd unit file

prodip@odoo-droplet:~$ sudo nano /etc/systemd/system/odoo.service

Copy the following line to this file

[Unit]

Description=Odoo
Requires=postgresql.service
After=network.target postgresql.service

[Service]
Type=simple
SyslogIdentifier=odoo
PermissionsStartOnly=true
User=odoodbuser
Group=odoodbuser
ExecStart=/home/odoodbuser/myodoo15-venv/bin/python3 /home/odoodbuser/odoo/odoo-bin -c /etc/odoo.co>StandardOutput=journal+console

[Install]
WantedBy=multi-user.target

Save the added content and move to the next step

Reload systemd daemon

prodip@odoo-droplet:~$ sudo systemctl daemon-reload

Enable Odoo15 service

prodip@odoo-droplet:~$ sudo systemctl enable --now odoo.service
Created symlink /etc/systemd/system/multi-user.target.wants/odoo.service → /etc/systemd/system/odoo.service.
prodip@odoo-droplet:~$

Check Odoo15 status

prodip@odoo-droplet:~$ sudo systemctl status odoo.service
● odoo.service - Odoo
     Loaded: loaded (/etc/systemd/system/odoo.service; enabled; preset: enabled)
     Active: active (running) since Thu 2023-04-13 12:36:39 UTC; 8s ago
   Main PID: 22752 (python3)
      Tasks: 4 (limit: 2322)
     Memory: 72.8M
        CPU: 1.938s
     CGroup: /system.slice/odoo.service
             └─22752 /home/odoodbuser/myodoo-venv/bin/python3 /home/odoodbuser/odoo/odoo-bin -c /etc/odoo.conf

Apr 13 12:36:39 odoo-droplet systemd[1]: Started Odoo.
prodip@odoo-droplet:~$

Web server configuration

Install nginx

prodip@odoo-droplet:~$ sudo apt install nginx

Enable nginx through firewall

prodip@odoo-droplet:~$ sudo ufw app list
Available applications:
  Nginx Full
  Nginx HTTP
  Nginx HTTPS
  OpenSSH
prodip@odoo-droplet:~$ sudo ufw allow "Nginx Full"
Rule added
Rule added (v6)
prodip@odoo-droplet:~$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)

prodip@odoo-droplet:~$

Create a Nginx Server Block for your Domain/server

prodip@odoo-droplet:~$ sudo nano /etc/nginx/sites-available/odooserver

/etc/nginx/sites-available/odooserver

upstream odoo {
   server 127.0.0.1:8069;
}

server {
   listen 80;
   server_name 159.89.14.54;

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

   proxy_buffers 16 64k;
   proxy_buffer_size 128k;

   location / {
      proxy_pass http://odoo;
      proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
      proxy_redirect off;

      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto https;
   }

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

Save and close the file when you are finished. Now, you can enable the file by linking it to the sites-enabled directory

prodip@odoo-droplet:~$ sudo ln -s /etc/nginx/sites-available/odooserver /etc/nginx/sites-enabled

Test your Nginx configuration for syntax errors by typing

prodip@odoo-droplet:~$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
prodip@odoo-droplet:~$

Now restart the nginx server

prodip@odoo-droplet:~$ sudo systemctl restart nginx.service

Setting up the erp

Open up the url and paste the droplet’s ip address to the address bar

Give the credentials. If everything is okay you should be redirected to the following page

Give your credentials and you are good to go!

Leave a Reply

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