In this post, I will show you how to setup odoo port 80 so that users can easily access the service without typing the port number (say, 8069). This means that you can access your odoo instance as example.com instead of example.com:8069.
Our deployment will involve running the odoo instance as a mod_wsgi script. To achieve this, we will create a wsgi script file as well as a new configuration file for apache to handle incoming requests.
First, we need to install apache web server. Many OS distributions under major VPS offerings will have this already set up. It is therefore worth checking using the command:
sudo service apache2 status
However, if apache is not installed, install it by running the following command on terminal:
sudo apt-get install apache2
In many cases, the mod_wsgi module is not installed and enabled in apache out of the box. We therefore need to install and enable it using the following commands.
sudo apt-get install libapache2-mod-wsgi
sudo a2enmod wsgi
Create odoo wsgi script
This mod_wsgi script will run the odoo instance behind apache web server.
Navigate to the directory where odoo is installed and create a file called odoo-wsgi.py with the following contents. In my case, odoo is installed under /opt/odoo. (Note that that is the directory that contains odoo-bin in version 10 and 11 or odoo.py file.
# WSGI Handler configuration file.
odoo.multi_process = True
# Equivalent of --load command-line option
odoo.conf.server_wide_modules = ['web'] conf = odoo.tools.config
# Path to the Odoo Addons directory/directories (comma-separated )
conf['addons_path'] = '/opt/odoo/odoo/addons,/opt/odoo/addons,/opt/odoo/custom/addons'
# Optional database config if not using local socket
conf['db_name'] = 'demo_db_name'
conf['db_host'] = 'localhost'
conf['db_user'] = 'odoo'
conf['db_port'] = 5432
conf['db_password'] = False
conf['xmlrpc_port'] = 8069
# Generic WSGI handlers application
application = odoo.service.wsgi_server.application
# Standard OpenERP XML-RPC port is 8069
bind = '127.0.0.1:8069'
pidfile = '.gunicorn.pid'
workers = 4
timeout = 240
max_requests = 2000
sudo vi /etc/apache2/sites-enabled/odoo.conf
ServerName example.com ServerAlias *.example.com // You can achieve dbfillter using subdomains here WSGIScriptAlias / /opt/odoo/odoo-wsgi.py WSGIDaemonProcess oe user=odoo group=odoo processes=4 python-path=/opt/odoo/ display-name=apache-odoo-server python-home=/opt/ou11_venv/bin/ WSGIProcessGroup oe ErrorLog /var/log/odoo/odoo-error.log CustomLog /var/log/odoo/odoo-server.log combined Require all granted
The python-home argument is the path to your python virtual environment on the apache wsgi script. Remove that if you are not using a virtual environment to run your odoo instance (highly recommended).
I had a few issues running Odoo 11 as a wsgi script. After hours of seraching why my venv was not getting the required packages, I figured that there’s a separate version of wsgi_mod for python 3. To set it up:
- You probably already have mod_wsgi (for python 2>) So you need to uninstall it.
- Then install the right version of wsgi_mode for python 3
a2dismod wsgi sudo apt-get remove libapache2-mod-wsgi
$ sudo apt-get install libapache2-mod-wsgi-py3
$ a2enmod wsgi