Odoo in one of the most commonly used business applications at the moment. It can be configured to use sub-domain filtering so the users can run different Odoo databases on different sub-domains. This means you can have different Odoo website/application for different branch of your company. The Odoo sub-domain filtering is simple to configure, so if you have a Linux VPS with Odoo installed on it, you can follow this guide.
The first step is to install mod_wsgi on your server. If you have a CentOS VPS, you can run the command:
yum install mod_wsgi
Or, if you have an Ubuntu VPS, you can run these commands to install and enable the same Apache module:
apt-get install libapache2-mod-wsgi a2enmod wsgi
Next step is to add the ‘dbfilter = ^%d$’ to your Odoo configuration file. Open your Odoo configuration file using your favorite text editor and add the following line:
dbfilter = ^%d$
We assume that your Odoo configuration file is saved in your /etc directory, so to edit the file using the ‘nano’ text editor you need to run:
nano /etc/odoo-server.conf
Next, open the ‘/opt/odoo/openerp/tools/config.py’ file
nano /opt/odoo/openerp/tools/config.py
and change:
"--db-filter", dest="dbfilter", my_default='.*'
to:
"--db-filter", dest="dbfilter", my_default='%d'
We assume that your Odoo is installed in your /opt directory. If Odoo is installed in another directory, you should find and edit the corresponding file.
One of the last things you need to do is to create an Apache virtual host. The Apache virtual host should contain the following lines:
<VirtualHost *:80> ServerName example.com ServerAlias *.example.com WSGIScriptAlias / /opt/odoo/openerp-wsgi.py WSGIDaemonProcess oe user=odoo group=odoo processes=2 python-path=/opt/odoo/ display-name=apache-odoo WSGIProcessGroup oe ErrorLog /var/log/odoo/odoo-error.log CustomLog /var/log/odoo/odoo-access.log combined <Directory /opt/odoo> #Order allow,deny #Allow from all Options All AllowOverride All Require all granted </Directory> </VirtualHost>
Again, you can edit the virtual host to match your needs. Of course, you need to use a valid domain name which should be pointed to your server IP address.
In order to get the Odoo sub-domain filter to work, you need to create sub-domains and point them to your Linux VPS IP address. To complete this task, you need to edit the zone file of your domain name.
Last but not least, you need to create separate databases for your sub-domains. Open your favorite web browser and navigate to:
http://example.com:8069/web/database/manager
Change example.com with your domain name. Here, you need to create new databases to match your sub-domains. For instance, if you like to have a separate database for your sales department and your sales.example.com sub-domain, you need to create a ‘sales’ database. After you complete this step, you need to restart your Apache web server and your Odoo. You should be able to access your new Odoo database and test the sub-domain filtering at:
http://sales.example.com:8069
Of course you don’t have to do any of this if you use one of our Linux VPS hosting services, in which case you can simply ask our expert Linux admins to configure Odoo subdomain filtering for you. They are available 24×7 and will take care of your request immediately. For newer versions, you might also want to consider reading: How to Install Odoo 10 with subdomain filtering.
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.
Thank you for this straight forward guide. I have a question though. I know that if I create a new database from the main domain, say example.com, it becomes accessible if the user visits example.com. How then can I set an already existing database to act as the default if user visits example.com instead of sales.example.com?
%d is replaced by the subdomain the request is made on, with the exception of www
example.com and www.example.com both match the database example
sales.example.com match the database sales
subdomain.example.com match the database subdomain