In this tutorial I will teach you how to separate your Odoo frontend and backend. I will install the Odoo codebase/frontend on one server and the backend (your PostgreSQL server and database) on another server. You will learn how to configure both Odoo and PostgreSQL to achieve this.
1. Introduction
In order to achieve and demonstrate this setup to you I will be working with two virtual machines.
I will refer to the Odoo codebase/frontend server as the ‘frontend server’. The PostgreSQL server and database will be named ‘backend server’ throughout this tutorial.
My frontend server has the IP 192.168.118.167 and my backend server has the IP 192.168.118.168.
Tip: Make sure that both your servers have a fixed IP, otherwise your setup will break due to IP changes!
2. Configuring the backend server
Let us start with the configuration of the backend server. This server will contain the PostgreSQL server and the database(s).
2.1 Installing postgreSQL
Open up a terminal on your backend server and install PostgreSQL if you haven’t yet:
1 |
sudo apt-get install postgresql -y |
2.2 Creating the PostgreSQL user
Now create a new PostgreSQL user. Make sure that the PostgreSQL username matches with the username of the user running Odoo on your frontend server. In my example I will create a new PostgreSQL user with the name “odoo11”:
1 |
sudo su - postgres -c "createuser -s odoo11 -P" |
After you execute this command the system will ask you for a password for this user. Fill in a password and confirm this password again.
Tip: Don’t forget to remember this password, you’ll need it later on.
2.3 Configuring pg_hba.conf
After installing the PostgreSQL server and creating the user we now need to configure the remote connections. As our backend server will be used for the database connections our frontend server needs to be able to access it. Open up your frontend server and get the IP of the server. In my example my frontend server has the IP 192.168.118.167. Now open up your pg_hba.conf file on your backend server:
1 |
sudo nano /etc/postgresql/9.5/main/pg_hba.conf |
Scroll in this file and search for the following line of code:
1 2 |
# IPv4 local connections: host all all 127.0.0.1/32 md5 |
Add a new line after the existing one which contains your frontend server its IP address. As you don’t want to use the exact IP address you should use the /24 subdomain. In my example this results to 192.168.118.0/24 instead of 192.168.118.167. Your configuration file should now look like this:
1 2 3 4 |
# IPv4 local connections: host all all 127.0.0.1/32 md5 host all all 192.168.118.0/24 md5 |
Finally, save your file and close it. Your PostgreSQL now knows that you want to allow connections from the backend server (IP 192.168.118.167).
2.4 Configuring postgresql.conf
Your PostgreSQL still needs to know the listen address of your frontend server too though. To achieve this we have to edit the postgresql.conf file:
1 |
sudo nano /etc/postgresql/9.5/main/postgresql.conf |
Find the ‘listen_addresses’ line, which looks like this by default:
1 |
#listen_addresses = 'localhost' |
Now add in the IP of your frontend Odoo server (in my example 192.168.118.192):
1 |
listen_addresses = 'localhost,192.168.118.168' |
Tip: Don’t forget to remove the # in this line because otherwise this line will be skipped!
Save this file and close it.
You’ve now applied all the changes that you need to do on the backend server. Next reload the PostgreSQL service in order to apply all the changes:
1 |
sudo service postgresql reload |
3. Configuring the frontend server
Your backend server is done now. Switch to the frontend server and open up your Odoo configuration file.
Tip: If you haven’t installed an Odoo yet you can follow my tutorial here
Typically your Odoo configuration file is under /etc/ and is named your-odoo.conf:
1 |
sudo nano /etc/odoo11-server.conf |
Add or change the following parameters in the configuration file:
1 2 3 4 5 6 |
[options] admin_passwd = mysupersecretpassword db_host = 192.168.118.168 # This is the IP of the backend server db_port = 5432 db_user = odoo11 # The PostgreSQL user you've configured in chapter 2.2. db_password = yourpassword # The PostgreSQL user his password you've set in chapter 2.2 |
Finally, restart your Odoo service to reload your Odoo configuration:
1 |
sudo service odoo11-server restart |
When you now browse to your Odoo instance (on your frontend server) you’ll see that your new Odoo is ready to use.
That is all! You’ve now setup your own Odoo instance where the frontend and backend are split between two servers.
4. Tips
While this is everything that you need in order to split up the backend and frontend of Odoo there are still some things to consider.
Because of security reasons you’ll most likely want to encrypt all the data and place everything on SSL. This also includes the calls from the frontend server to the backend server.
After you’ve created a new database you should check if the database is in fact created on the backend server instead of on the frontend server. You can do this executing the following commands (one by one) on your backend server:
1 2 3 |
sudo su postgres psql \l |
After running these commands you can see an overview of your databases and to what user the database belongs. In my example you can see a new database named ‘ABC’ which is owned by my Odoo/PostgreSQL user ‘odoo11’:
5. Conclusion
Setting up an Odoo instance where the frontend and the backend are split is actually quite easy. Due to the built-in parameters from Odoo it is very easy to configure the frontend side. When you split the frontend and backend up and apply extra security – such as HTTPS connections and VLAN’s – you’ll have a safer and more controlable Odoo instance.
If you’d like to learn more about the deployment of servers and the default Odoo parameters you can have a look at the official documentation.
Has this tutorial helped you, do you have any feedback or questions? Post away!