When using a Debian distribution, by default your login is root
with administrator powers, and your command prompt shows #
. When using Ubuntu, logging with the root
account is disabled, and the initial user configured during the installation process is a sudoer, meaning that it is allowed to use the sudo
command to run commands with root privileges.
First, we should update the package index, and then perform an upgrade to make sure all installed programs are up to date:
$ sudo apt-get update $ sudo apt-get upgrade -y
Next, we will install the PostgreSQL database, and make our user a database superuser:
$ sudo apt-get install postgresql -y $ sudo su -c "createuser -s $(whoami)" postgres
We will be running Odoo from source, but before that we need to install the required dependencies. These are the Debian packages required:
$ sudo apt-get install git python-pip python2.7-dev -y $ sudo apt-get install libxml2-dev libxslt1-dev libevent-dev \ libsasl2-dev libldap2-dev libpq-dev libpng12-dev libjpeg-dev \ poppler-utils node-less node-clean-css -y
We should not forget to install wkhtmltox
, which is needed to print reports:
$ wget http://nightly.odoo.com/extra/wkhtmltox-0.12.1.2_linux-jessie-amd64.deb $ sudo dpkg -i wkhtmltox-0.12.1.2_linux-jessie-amd64.deb $ sudo apt-get -fy install
The installation instructions will report a missing dependencies error, but the last command forces the installation of those dependencies and correctly finishes the installation.
Now we are only missing the Python packages required by Odoo. Many of them also have Debian/Ubuntu system packages. The official Debian installation package uses them, and you can find the package names in the Odoo source code, in the debian/control
file.
However, these Python dependencies can be also installed directly from the Python Package Index (PyPI). This is friendlier for those who prefer to install Odoo in virtualenv
. The required package list is in the Odoo's requirements.txt
file, as is usual for Python-based projects. We can install them with these commands:
$ sudo -H pip install --upgrade pip # Ensure pip latest version $ wget https://raw.githubusercontent.com/odoo/odoo/10.0/requirements.txt $ sudo -H pip install -r requirements.txt
Now that we have all dependencies installed, database server, system packages, and Python packages, we can install Odoo.
A good security practice is to run Odoo using a dedicated user, with no special privileges on the system.
We need to create the system and database users for that. We can name them odoo-prod
, for example:
$ sudo adduser --disabled-password --gecos "Odoo" odoo $ sudo su -c "createuser odoo" postgres $ createdb --owner=odoo odoo-prod
Here, odoo
is the username and odoo-prod
is the name of the database supporting our Odoo instance.
Note that these are regular users without any administration privileges. A home directory is automatically created for the new system user. In this example, it is /home/odoo
, and the user can refer to its own home directory with the ~
shortcut symbol. We will use it for that user's Odoo specific configurations and files.
We can open a session as this user using the following command:
$ sudo su odoo
The exit
command terminates that session and returns to our original user.
Sooner or later, your server will need upgrades and patches. A version controlled repository can be of great help when the time comes. We use git
to get our code from a repository, just like we did to install the development environment.
Next, we will impersonate the odoo
user and download the code into its home directory:
$ sudo su odoo $ git clone https://github.com/odoo/odoo.git /home/odoo/odoo-10.0 -b 10.0 --depth=1
The -b
option makes sure that we get the right branch, and the --depth=1
option ignores the change history and retrieves only the latest code revision, making the download much smaller and faster.
Git will surely be an invaluable tool to manage the versions of your Odoo deployments. We just scratched the surface of what can be done to manage code versions. If you're not already familiar with Git, it's worth learning more about it. A good starting point is http://git-scm.com/doc.
By now we should have everything needed to run Odoo from source. We can check that it starts correctly and then exit from the dedicated user's session:
$ /home/odoo/odoo-10.0/odoo-bin --help $ exit
Next, we will set up some system-level files and directories to be used by the system service.
Adding the --save
option when starting an Odoo server saves the configuration used to the ~/.odoorc
file. We can use the file as a starting point for our server configuration, which will be stored at /etc/odoo
, as shown in the following code:
$ sudo su -c "~/odoo-10.0/odoo-bin -d odoo-prod --save --stop-after-init" odoo
This will have the configuration parameters to be used by our server instance.
Next, we need to place the config file in the expected location:
$ sudo mkdir /etc/odoo $ sudo cp /home/odoo/.odoorc /etc/odoo/odoo.conf $ sudo chown -R odoo /etc/odoo
We should also create the directory where the Odoo service will store its log files. This is expected to be somewhere inside /var/log
:
$ sudo mkdir /var/log/odoo $ sudo chown odoo /var/log/odoo
Now we should make sure that a few important parameters are configured. Here are suggested values for the most important ones:
[options] addons_path = /home/odoo/odoo-10.0/odoo/addons, /home/odoo/odoo-10.0/addons admin_passwd = False db_user = odoo-prod dbfilter = ^odoo-prod$ logfile = /var/log/odoo/odoo-prod.log proxy_mode = True without_demo = True workers = 3 xmlrpc_port = 8069
Let's explain them:
addons_path
is a comma-separated list of the paths where add-on modules will be looked up. It is read from left to right, with the leftmost directories having a higher priority.admin_passwd
is the master password to access the web client database management functions. It's critical to set this with a strong password or, even better, to set it to False
to deactivate the function.db_user
the database instance to initialize during the server startup sequence.dbfilter
is a filter for the databases to be made accessible. It is a Python-interpreted regex expression. For the user to not be prompted to select a database, and for unauthenticated URLs to work properly, it should be set with ^dbname$
, for example, dbfilter=^odoo-prod$
. It supports the %h
and %d
placeholders, that are replaced by the HTTP request hostname and subdomain name.logfile
is where the server log should be written. For system services the expected location is somewhere inside /var/log
. If left empty, or set to False
, the log print to standard output instead.proxy_mode
should be set to True
when Odoo is accessed behind a reverse proxy, as we will do.without_demo
should be set to True
in production environments so that new databases do not have demo data on them.workers
with a value of two or more enables multiprocessing mode. We will discuss this in more detail in a moment.xmlrpc_port
is the port number at which the server will listen. By default, port 8069
is used.The following parameters can also be helpful:
data_dir
is the path where session data and attachment files are stored. Remember to have backups on itxmlrpc-interface
sets the addresses that will be listened to. By default, it listens to all 0.0.0.0
, but when using a reverse proxy, it can be set to 127.0.0.1
in order to respond only to local requestsWe can check the effect of the settings made by running the server with the -c
or --config
option as follows:
$ sudo su -c "~/odoo-10.0/odoo-bin -c /etc/odoo/odoo.conf" odoo
Running Odoo with the above settings won't display any output to the console, since it is being written to the log file defined in the configuration file. To follow what is going on with the server we need to open another terminal window, and run there:
$ sudo tail -f /var/log/odoo/odoo-prod.log
If is also possible to use the configuration file and still force the log output to be printed to the console, by adding the --logfile=False
option, like this:
$ sudo su -c "~/odoo-10.0/odoo-bin -c /etc/odoo/odoo.conf --logfile=False" odoo