Wednesday, May 4, 2016

Install Odoo 9 on Ubuntu 14.04


This guide covers how to install and configure Odoo in just 35 minutes using Git source so it will be easy to upgrade, maintain and customize.

Before You Begin

Log in to your Linode via SSH and check for updates using apt-get package manager.


sudo apt-get update && sudo apt-get upgrade

Open Corresponding Firewall Ports

In this case we’re using Odoo’s default port 8069, but this could be any port you specify later in the configuration file.

sudo ufw allow ssh
sudo ufw allow 8069/tcp
sudo ufw enable

Install Database and Server Dependencies

Now we’re going to install the PostgreSQL database and other necesary server libraries  using  apt-get
sudo apt-get install subversion git bzr bzrtools python-pip postgresql postgresql-server-dev-9.3 python-all-dev python-dev python-setuptools libxml2-dev libxslt1-dev libevent-dev libsasl2-dev libldap2-dev pkg-config libtiff5-dev libjpeg8-dev libjpeg-dev zlib1g-dev libfreetype6-dev liblcms2-dev liblcms2-utils libwebp-dev tcl8.6-dev tk8.6-dev python-tk libyaml-dev fontconfig
Create Odoo User and Log Directory
Create the Odoo system user.


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

change or set odoo user password
sudo passwd odoo
it will ask for new password of odoo user 
enter new password as you want for odoo user 

for login to odoo user (optional)

sudo su - odoo -s /bin/bash



Create the log directory.

sudo mkdir /var/log/odoo


Install Odoo Server Files from Source

Change to the Odoo directory, in our case:

cd /opt/odoo/

Clone the Odoo files on your server.

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


Create PostgreSQL User

Switch to postgres user.
sudo su - postgres
But, if you’re deploying a Production server you may want to set a strong password for the database user.

createuser odoo -U postgres -dRSP
You’ll be prompted for a password, save it, we’ll need it shortly.
Press CTRL+D to exit from postgres user session.



Specific Dependencies for Odoo Applications


Using pip instead of apt-get will guarantee that your installation has the correct versions needed. We’ll also abstain of using Ubuntu’s packaged versions of Wkhtmltopdf and node-less.

Install Python Dependencies

Install Python libraries using the following commands:
sudo pip install -r /opt/odoo/doc/requirements.txt
sudo pip install -r /opt/odoo/requirements.txt


Install Less CSS via nodejs and npm.

Download nodejs installation script from nodesource.
wget -qO- https://deb.nodesource.com/setup | sudo bash -

Now that our repository list is updated install nodejs using apt-get.

sudo apt-get install nodejs

Time to install a newer version of Less via npm.

sudo npm install -g less less-plugin-clean-css


Install Updated Wkhtmltopdf Version

Switch to a temporally directory of your choice.
cd /tmp

Download the recommended version of wkhtmltopdf for Odoo server, currently 0.12.1

sudo wget http://download.gna.org/wkhtmltopdf/0.12/0.12.1/wkhtmltox-0.12.1_linux-trusty-amd64.deb

Install the package using dpkg.

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

To function properly we’ll need to copy the binaries to an adequate location.

sudo cp /usr/local/bin/wkhtmltopdf /usr/bin
sudo cp /usr/local/bin/wkhtmltoimage /usr/bin


Odoo Server Configuration

Copy the included configuration file to a more convenient location changing it’s name toodoo-server.conf

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

Next we need to modify the configuration file. The finished file should look similar to this depending on your deploying needs:
File :- /etc/odoo-server.conf

[options]
admin_passwd = admin
db_host = False 
db_port = False
db_user = odoo
db_password = <PostgreSQL_user_password>
addons_path = /opt/odoo/addons
logfile = /var/log/odoo/odoo-server.log
xmlrpc_port = 8069


  • admin_passwd = admin This is the password that allows database operations.
  • db_host = False Unless you plan to connect to a different database server address, leave this line untouched.
  • db_port = False Odoo uses PostgreSQL default port 5432, change only if necessary.
  • db_user = odoo Database user, in this case we used the default name.
  • db_password = The previously created PostgreSQL user password.
  • addons_path = We need to modify this line to read: addons_path = /opt/odoo/addons. Add</path/to/custom/modules> if needed.
  • We need to include the path to log files adding a new line:logfile = /var/log/odoo/odoo-server.log
  • Optionally we could include a new line specifying the Odoo Frontend port used for connection: xmlrpc_port = 8069. This only makes sense if you’re planning to run multiple Odoo instances (or versions) on the same server. For normal installation you could skip this line and Odoo will connect by default to port 8069.


Odoo Boot Script

Next step is creating a boot script odoo-server to gain control over Odoo behavior and use it at server startup and shutdown.
File :- /etc/init.d/odoo-server
#!/bin/sh
### BEGIN INIT INFO
# Provides: odoo-server
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Odoo ERP
# Description: Odoo is a complete ERP business solution.
### END INIT INFO

PATH=/bin:/sbin:/usr/bin
# Change the Odoo source files location according your needs.
DAEMON=/opt/odoo/openerp-server
# Use the name convention of your choice 
NAME=odoo-server
DESC=odoo-server

# Specify the user name (Default: odoo).
USER=odoo

# Specify an alternate config file (Default: /etc/odoo-server.conf).
CONFIGFILE="/etc/odoo-server.conf"

# pidfile
PIDFILE=/var/run/$NAME.pid

# Additional options that are passed to the Daemon.
DAEMON_OPTS="-c $CONFIGFILE"

[ -x $DAEMON ] || exit 0
[ -f $CONFIGFILE ] || exit 0

checkpid() {
[ -f $PIDFILE ] || return 1
pid=`cat $PIDFILE`
[ -d /proc/$pid ] && return 0
return 1
}

case "${1}" in
start)
echo -n "Starting ${DESC}: "

start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--chuid ${USER} --background --make-pidfile \
--exec ${DAEMON} -- ${DAEMON_OPTS}

echo "${NAME}."
;;

stop)
echo -n "Stopping ${DESC}: "

start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
--oknodo

echo "${NAME}."
;;

restart|force-reload)
echo -n "Restarting ${DESC}: "

start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
--oknodo

sleep 1

start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--chuid ${USER} --background --make-pidfile \
--exec ${DAEMON} -- ${DAEMON_OPTS}

echo "${NAME}."
;;

*)
N=/etc/init.d/${NAME}
echo "Usage: ${NAME} {start|stop|restart|force-reload}" >&2
exit 1
;;
esac

exit 0


Odoo Files Ownership and Permissions

Change the odoo-server file permissions and ownership so only root can write to it, while odoo user will only be able to read and execute it.


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

Since odoo user will run the application, change its ownership accordingly.


sudo chown -R odoo: /opt/odoo/

We should set odoo user as the owner of log directory as well.

sudo chown odoo:root /var/log/odoo

Finally, we should protect the server configuration file changing its ownership and permissions so no other non-root user can access it.


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


Testing the Server

It’s time to check that everything is working as expected, lets start the Odoo server.
sudo /etc/init.d/odoo-server start
Let’s take a look at log file to verify no errors occurred.

cat /var/log/odoo/odoo-server.log

Now we can check if the server stops properly too.

sudo /etc/init.d/odoo-server stop
Enter the same command again.

cat /var/log/odoo/odoo-server.log


Running Boot Script at Server Startup and Shutdown

If the Odoo server log doesn’t indicate any problem we can continue and make the Boot script start and stop with the server.
sudo update-rc.d odoo-server defaults

It’s a good idea to restart our Server to see if everything is working

sudo shutdown -r now

Once restarted verify one more time the log file.

cat /var/log/odoo/odoo-server.log


Testing Odoo Frontend

Open a new browser window and enter in the address bar:
http://<your_domain_or_IP_address>:8069

A screen similar to this would show up.





Congratulations, now you can create your first database and start using Odoo!