Sunday, November 16, 2014

Installing Odoo version 8 on Ubuntu 14.04 LTS Server 64-bit

Odoo version 8
Now that you have already gone through the previous exercise to Install Ubuntu 14.04 LTS Server 64-bit.  It is time to get your Odoo version 8 up and running.  The first thing you want to do if you have not already done it is to make sure that you have a fully patched system.  This was one of the last steps in the Ubuntu 14.04 Installation, so if you just finished that, then you should be good.  I will add it here anyway for those of you who installed Ubuntu prior and need to updated your systems.


So for those of you who need to update your system because either you have not done it yet, or it has been a while since you installed Ubuntu here is how you update your server installation.  You will most likely need to run sudo in front of teh apt-get commands since you probably have logged in as your user.  If you remember from last time sudo allows you to run commands as root or the super user (sudo stands for super user do).


sudo apt-get update
sudo apt-get dist-upgrade

Typically you will not have to reboot unless there is a major update, something like a kernel update.  But personally I like to reboot at this point anyway since the server is not in production and it just ensures everything comes back up.

sudo reboot

Now that your system has come back up you will need to login again, course if you did not reboot the system then you can just continue on.

Typically for security reasons you want to run applications as users and not root (super user).  This makes it significantly more difficult for the application to be used for nefarious actions.  Isolating the application by running it as a user also reduces the likelihood that the application can do harm to the system itself (other than filling up disk space).  So we are now going to create the user to run Odoo.  In this example the user will be named odoo.  I have also chosen to make the odoo user directory /top/odoo instead of where users typically have their home directory /home/{username}.  I did this because I am a little old school and believe applications should not be installed in the /home directory. In various Unix systems /opt is one place non-system applications are installed.  One other example is /usr/local/. 

sudo adduser --system --home=/opt/odoo --group odoo

Next we will install applications and supporting pearl modules that are required to make Odoo 8 run.  There are a couple things I will point out as we move through this section.

First since Odoo is dependent on having a database in place specifically PostgreSQL we will install and configure it first.

When you run the following command some dependencies will need to be installed to allow PostgreSQL to run properly.  

sudo apt-get install postgresql

You will see all the applications need to run PostgreSQL and you will prompted to to see if you want to install all these applications.  Press Y on your keyboard to install PostgreSQL and the supporting applications.

Now that PostgreSQL has been installed we have to change to the postgres user in order to be able to configure the database for Odoo.

sudo su - postgres

Next we need to create a database user for Odoo.  This will allow Odoo access to connect to PostgreSQL and create, modify, drop (delete) databases.  We will also be setting the database user with a password to ensure security.  You will need to remember the password as you will need it later when we are configuring Odoo to connect to the database.  I chose odoo for the database user odoo.  Just trying to keep it easy for now but I NEVER recommending doing this in a production environment.  Actually I probably would not do this an a development or QA environment either.  Since I am the only one with access to my system I am comfortable doing it in my environment and it won't be housing any type of production data.

createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt odoo

Enter password for new role: ********
Enter it again: ********


You are now done creating the database so you can logout as the posgtres user by running the following command:
exit

In order for Odoo 8 to run it has some python libraries which are required.  The next step is to install those libraries.  In addition we will install Git which will allow us to download Odoo shortly.

sudo apt-get install python-dateutil python-decorator python-docutils python-feedparser python-gdata python-gevent python-imaging python-jinja2 python-ldap python-libxslt1 python-lxml python-mako python-mock python-openid python-passlib python-psutil python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-pypdf python-reportlab python-requests python-simplejson python-tz python-unittest2 python-vatnumber python-vobject python-werkzeug python-xlwt python-yaml git

For some reason the version of&nbsp wkhtmltopdf in the Ubuntu 14.04 repository is out of data at version 0.9.9.  Installing this version will give the Qweb templating engine in Odoo warning messages that wkhtmltopdf is out of data.  The wkhtmltopdf project on Sourcforge has an up to date version 0.12.1 already prepackaged and ready to install on their website for Ubuntu 14.04.  Now the link below will download it for you.

NOTE - If you have not installed the 64-bit version of Ubuntu 14.04 then you will need to downlaod a different package than the one below.  To see your options just go to the wkhtmltopdf downloads area on their website or click the following link http://wkhtmltopdf.org/downloads.html.

So download the 64-bit version of wkthmltopdf by running the following command:

wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-trusty-amd64.deb

You will now need to install the application by running dpkg.  What is dpkg it stands for Debian Package. It is the way to install software manually on a system.  Since this correct version was not part of the repository we needed to manually download and install it....since we have already downloaded the file we just have to install it.

sudo dpkg -i wkhtmltox-0.12.1_linux-trusty-amd64.deb

Next we need to change user to odoo in order to download the Odoo files.  The reason this step is important is we want to run Odoo as our odoo user.  If you download and continued on through the process Odoo would run as your user which you don't want.  Even worse I have seen people run Odoo as the root user which is even worse since now you are running it as super user and it has full access to your server.

sudo su - odoo -s /bin/bash

Now that you have changed your user to the odoo user (I am trying to reinforce the fact you need to change to the odoo user via the command above before you more to the next section.

You will not download Odoo from GitHub.  Git is basically a software version control system and GitHub is a public place for developers to share code, whether it be some folks working on a project together or even better a business developing something to use in house or share with the world for profit of open source.  It has also been used for documentation and or scripts for installing various software including Odoo.  The next command will download all the Odoo code into the /opt/odoo directory.

git clone https://www.github.com/odoo/odoo --depth 1 --branch 8.0 --single-branch .

You no longer need to be logged in as the odoo user so you can logout as that user by running the next command.

exit

You are getting close to completion now so hang in there for just a little longer.  Next we are going to setup the configuration so Odoo will run on your server.  First thing we must do is create the configuration directory.  Most configuration files are located in /etc under their respective directories.  In this case our odoo configuration files will be located in /etc/odoo, but we have to create the directory first.

sudo mkdir /etc/odoo

When we downloaded everything from GitHub earlier into the odoo user directory it already has some configuration files that we can use.  We are going to change the names from openerp to odoo so it makes sense.  Make sure you do the next command as your account and not the odoo account as the odoo account does not have and should not have the ability to do sudo (superuser do).

sudo cp /opt/odoo/debian/openerp-server.conf /etc/odoo/odoo-server.conf

Since we have the configuration file moved into its directory we need to change the owner of the file to ensure it stays secure.  There are usernames and passwords kept in this file so we don't want ever user on the system to have access to this file.

sudo chown odoo: /etc/odoo/odoo-server.conf

The next command is restricting access to the file we are going to use chmod to do this and the number corresponds to the User, Group, Other access.  The way the numbers work is this each number correlates to a set of permissions for 0 = no access, 1 = execute ONLY, 2 = write ONLY, 4 = read ONLY.  So then you can use combinations of those numbers by adding them together like the example below.  User = 6 so the user can Read (4) and Write (2) the file (6), The group associated with this file can only Read (4), and all other users have not access to the file (0).  Thus the 640 after the command.

sudo chmod 640 /etc/odoo/odoo-server.conf

We need to edit the file to set the configuration for our environment.  First I always like to back files up just in case we mess something up. I typically have the following naming convention for when I edit files. If I am making a copy of the original then I would copy the file with a -ORIG at the end (if I am not the only admin then I will have my intials on it as well) like the example below.
sudo cp /etc/odoo/odoo-server.conf /etc/odoo/odoo-server.conf-bln.ORIG

Any subsequent changes to the file I typically  use my initials and  the date. This is more important when you have more than one admin on the system so the next person can see what you did.  As an example of this you can see what I have done below.

sudo cp /etc/odoo/odoo-server.conf /etc/odoo/odoo-server.conf-bln.141116

Since we have made a backup of the original file we can now turn our attention to the changes in the file.

sudo vi /etc/odoo/odoo-server.conf

You will need to change the db_password = False to the password you chose early on during the install.  You remember when I told you to remember the password because you would need it later..now is later :).  I chose odoo when I setup mine to make it easy.

You also need to change the addons_path to look like this addons_path = /opt/odoo/addons

Also add the following logfile = /var/log/odoo/odoo-server.log

A special thank you to Patrick Aymar for pointing out that db_host needs to be set to /tmp (db_host = /tmp) in order for psycopg2.  This is due to the fact that the socket for PostgreSQL is located in /tmp instead of /var/run/postgresql/.

As a note when modifying files especially where there is more than one admin, or better yet so you can remember what you did later, use the comments.  This conf files uses the semi-colon as the comment character.  So I copied each line I was going to change, put the semi-colon in front of one and then made the modification on the copy.  For new lines like the logfile entry I added a comment prior to adding the logfile line.  Below is an example of my odoo-server.conf file
/etc/odoo/odoo-server.conf

NOTE - Later when you have Odoo working, if you were to go back and look at this file there will some major changes don't be aware that is normal.

Now it it time to setup the startup files to make sure Odoo starts anytime the server is rebooted.  Within the Odoo download we got from GitHub earlier this is a startup script that we will use.  It is not perfect but close and we can make a couple of edits and it will work perfect.  So go ahead and make a copy of the file from the /opt/odoo/debian directory and put it in the /etc/init.d directory using the following command:

sudo cp /opt/odoo/debian/init /etc/init.d/odoo-server

NOTE - We changed the name of the file from init to odoo-server. We did that in order to find the startup file for Odoo easier should we need to come back and make any changes to this file.

Next we need to modify the file. I did not make a copy of this file to -ORIG this time since we actually copied this file from /opt/odoo/debian with the previous command, to edit use the following command below:

sudo vi /etc/init.d/odoo-server

There are only a couple of changes you need to make to this file.  I modified teh DAEMON variable to point to the location where I installed Odoo.  It is not longer /usr/bin but now /opt/odoo.

I changed the CONFIG variable to point to our config file. Note that I only really change openerp-server.conf to odoo-server.conf in the config.  I also made comments like above copying the line I was going to change putting a # in front since that is the comment character for this file and made changes to the second line.

I also changed the NAME and DESC variable to Odoo-Server instead of just odoo.

So the top of your files should look like this:
/etc/init.d/odoo-server file

Next you need to modify the permissions to this file. Most of the time system start files are owned by the root users (superuser).  Since it is root's file the file can have full access (7) for root, and group and other can have execute + read (1+4=5).  It is not uncommon for everyone to have execute+read on these startup files...does not mean that it will run just means someone can try :)

sudo chown root: /etc/init.d/odoo-server
sudo chmod 755 /etc/init.d/odoo-server 

In the /etc/odoo/odoo-server.conf file we defined the log file and its location.  We said the log should be located in /var/log/odoo.  Most log files in Unix are located in /var/log.  Many applications use their own directory in order to house their log file.  That is what we are going to do for this exercise so we need to create the directory for the log files.


sudo mkdir /var/log/odoo

Since we don't want everyone to have access to the log files we can set the ownership of the log directory to odoo and the group root also having access.  After the command the first name is the user then a colon (:) and the second is the group followed by the file or in this case the directory.

sudo chown odoo:root /var/log/odoo

We are not quite done, but lets go ahead and test what we have done so far to see if we can start Odoo.  Run the following command.

sudo /etc/init.d/odoo-server start

You should have seen the system come back and tell you that Odoo-Server has started OK.  But we are going to verify a couple more ways.  The first command checks to see if the port is open for you to connect with your web browser.  The second command allows you to look for the Odoo process. 

netstat -a | more

This should give you the following showing you the port is available
tcp        0      0 *:8069                  *:*                     LISTEN

ps aux | grep odoo

This should show you the Odoo process

odoo       997  0.3  5.9 998448 121688 ?       Sl   11:33   1:06 python /opt/odoo/openerp-server --config /etc/odoo/odoo-server.conf --logfile /var/log/odoo/odoo-server.log

It looks like everything works if you are seeing similar information above.  I you like you can point a browser to the IP address of your Odoo server and add :8069 to the end.  For instance

http://10.0.1.43:8069 and you should get a page that looks like this:


Odoo 8 Initial Screen

If you see this page then you know you are on the home stretch...just a few more items and we are complete with the Odoo version 8 install.  Don't get hasty and start configuring things yet.  We will get to that in a few minutes.  For now we just want to make sure it works.

Since we know it works lets go ahead and stop Odoo.

sudo /etc/init.d/odoo-server stop

Next we need to go ahead and make sure Odoo starts everytime the server is restarted. The following command links the odoo-server file to all the startup rc directories.
sudo update-rc.d odoo-server defaults

If you want now just to make sure it all starts up okay, you can reboot your system

sudo reboot

When your system comes back up (I typically ping my server from another system for example ping 10.0.1.43 to know when it comes back up).  Point your browser to your server at port 8069 like you did before http://10.0.1.43:8069 (change my IP address for you server's IP address).  You should once again get a screen that looks like this:


Odoo Initial Screen


So not that you have Odoo up and running lets finish the setup using your web browser.  Since you already have the connected with your browser we are going to do two more things and then you can take a break.

I highly recommend changing the default password.  Click on Password on the left hand side and now you can set the password for Odoo in order to create and drop (delete) databases. It will ask you for the Master password the default is admin.  Now you can enter your new master password and then confirm. Should you ever forget your Master password it will be written to the /etc/odoo/odoo-server.conf file.


Odoo Change Master Password

Since you have secured your Master password you are ready to create for your first database.  This is the database your company will be setup to use for all exercises moving forward.  First enter your new Master password (hopefully you have not forgotten since the last section).  Enter your database name.  You can choose to add demonstration data in while you are learning the system.  Select your language and set the password for the Administrator user, click the Create Database button and you are complete.

Odoo Create New Database Screen

You are now complete.  Congratulation!  

NOTE - If you see a red hazard in the upper right of the screen, it is more likely due to the time zone being off on the user versus your browser.  The following steps are how to correct this issue.  If you don't have this issue then you are done now.

Odoo Local Modules Screen


 Modifying the time zone for the Admin user.  Click on Users on the left hand side of your browser window.  Now click on Administrator in oder to modify the Admin's settings.


Odoo Users Screen

When you click Administrator it will open a new window that looks like this.  Click the Edit button to the upper left of the Admins information.

Odoo - Admin User Screen

In the main part of the window click the Preferences tab.  Click the drop down next to Timezone to choose your timezone.  Click the red Save button to save your change.

Odoo - Edit Admin Timezone

 The hazard should have not gone away, if not refresh your browser and it will disappear.


Odoo - Saved admin



Once again congratulations you have successfully installed Odoo version 8 on your Ubuntu 14.04 LTS 64-bit server.  Since you probably will not always want to add the port number of your Odoo server in your web browser we will actually go through how to setup a proxy server that will mask the port number and allow you to use just a hostname or IP address to connect to your odoo server.

In order to SSH to your box you will need to have an SSH client installed.  Most Linux and OS X systems come with an SSH client. If you are on Windows you have a few options.  You can always use Putty which is free.  But my favorite is SecureCRT by Van Dyke Software.  I have been using SecureCRT since the late 90s and have always been impressed by the the package, support and features.

I will be creating two posts next week, the first post will be how to setup Nginx and the second post will be setting up Apache.  Both work fine and there is a great debate over which is better. I wont really be going into that as there are plenty of articles about that.  I just want to give you the option so you can choose the best one for you.