Wednesday, October 12, 2011

Installing OpenERP 6 Server on Mac OS X 10.6 (Snow Leopard)

Installing OpenERP Server
Step 1: We're going to use MacPorts to install the dependencies required by OpenERP. The latest version at the time of this writing is 2.0.1 but any later version should work and install the same. Download the version of MacPorts for Snow Leopard and run the installer package to get started. NOTE: MacPorts requires the Xcode developer tools. They can be found on your Mac OS X 10.6 Install DVD or downloaded from the Apple Developer Connection website.

Step 2: Join the Apple Developer Connection (their FREE membership will suffice) and download/install the Java for Mac OS X 10.6 Developer Package which contains the Java header files required by some of the dependencies.

Step 3: Install PostgreSQL 9.0.4 using the EnterpriseDB bundle available here. During the installation it will ask you where you want certain files installed. I used the following settings for organizational reasons:

  • Installation Directory: /Library/PostgreSQL/9.0
  • Data Directory: /Library/Server/PostgreSQL/Data 
  • Server Port: 5432
Open /Applications/Utilities/Terminal.app and type in the following commands to add the PostgreSQL bin directory to the database user's PATH:

johndoe$ sudo -i
Password: *enter your user password here*
root# export PGHOME=/Library/PostgreSQL/9.0
root# echo 'export PATH=/Library/PostgreSQL/9.0/bin:$PATH' >> $PGHOME/.profile
root# exit
logout


Step 4: We need to create a database user account that OpenERP will use to connect to PostgreSQL. The following commands should be entered into Terminal.app to create the openerp database user:

johndoe$ sudo su - postgres
Password: *enter your user password here*
postgres$ createuser --createdb --no-createrole --pwprompt openerp
Enter password for new role: *enter the openerp database user's password*
Enter it again: *enter the openerp database user's password - again*
Shall the new role be a superuser? (y/n) n
Password: *enter the postgres user's password*
postgres$ exit
logout


Step 5: Type the following commands into Terminal.app to install the OpenERP Server dependencies:

johndoe$ sudo -i
Password: *enter your user password here*
root# port install python26
root# port select python python26
root# export PATH=/Library/PostgreSQL/9.0/bin:$PATH
root# port install py26-setuptools; easy_install setuptools
root# port install py26-psycopg2 +postgresql90; easy_install psycopg2
root# port install py26-reportlab; easy_install reportlab
root# port install py26-lxml; easy_install lxml
root# port install py26-tz; easy_install pytz
root# port install py26-yaml; easy_install PyYaml
root# port install py26-mako; easy_install mako
root# port install py26-dateutil; easy_install DateUtils
root# port install graphviz +python26 +no_x11
root# port install py26-parsing; easy_install pyparsing
root# port install py26-pil; easy_install pil


Step 6: In order to run OpenERP securely we need to create an unprivileged system user. The following command displays a list of current users on the system - the numbers on the right are their user ids. You need to chose a unique user id that is not in the list for the new OpenERP user (preferable the next id in the 500 sequence).

root# dscl . -list /Users UniqueID
root# export NEW_USER_ID=*the unique id you have chosen for the openerp user*


Now we can run the following commands to create the new unprivileged openerp user:

root# dscl . -create /Users/openerp
root# dscl . -create /Users/openerp UniqueID $NEW_USER_ID
root# dscl . -create /Users/openerp NFSHomeDirectory /var/empty
root# dscl . -create /Users/openerp UserShell /bin/sh
root# dscl . -create /Users/openerp PrimaryGroupID 1
root# dscl . -create /Users/openerp RealName "OpenERP User"
root# dscl . -create /Users/openerp Password "*"
root# exit
logout


Step 7: Now that all the dependencies have been satisfied, download the OpenERP 6.0.2 Server Sources and move openerp-server-6.0.2.tar.gz to your Desktop. Double-click the archive to decompress and extract its contents. You should now have a directory named openerp-server-6.0.2 in your ~/Desktop folder. To install OpenERP Server run the following commands in Terminal.app:

johndoe$ cd ~/Desktop/openerp-server-6.0.2
johndoe$ sudo python setup.py install


Step 8: Now that OpenERP Server has been installed we need to configure it to run automatically when the computer is turned on, but first we need to configure the /Library/Server directory to secure the files we will put there. The following also creates a Logs folder where OpenERP Server logs will be stored.

johndoe$ sudo -i
Password: *enter your user password here*
root# cd /Library/Server
root# chown root:admin ./; chmod 0775 ./
root# chown -R postgres:wheel ./PostgreSQL; chmod 0770 ./PostgreSQL
root# mkdir -p ./OpenERP/Configuration
root# cd ./OpenERP
root# touch ./Configuration/openerp-server.conf
root# mkdir ./Logs
root# chown -R openerp:wheel ./; chmod -R 0770 ./


Use the following command to create the openerp-server.conf file in the /Library/Server/OpenERP/Configuration directory:

root# pico -w ./Configuration/openerp-server.conf

You can then paste the following into the text editor that opens. Make sure you update the file to include the correct admin_passwd and db_password:

[options]
without_demo = True
; This is the password that allows database operations:
admin_passwd = ***enter your database admin password here***
upgrade = False
verbose = False
netrpc = True
; netrpc_interface =
; netrpc_port =
xmlrpc = True
; xmlrpc_interface =
xmlrpc_port = 8069
db_host = localhost
db_port = 5432
; Please uncomment the following line *after* you have created the
; database. It activates the auto module check on startup.
db_name = False
db_user = openerp
db_password = ***enter the openerp database user password here***
; Uncomment these for xml-rpc over SSL
; secure = True
; secure_cert_file = /etc/openerp/server.cert
; secure_pkey_file = /etc/openerp/server.key
root_path = /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/openerp-server
soap = False
translate_modules = ['all']
demo = {}
addons_path = None
reportgz = False
; Static http parameters
static_http_enable = False
static_http_document_root = /var/www/html
static_http_url_prefix = /


Use Ctrl-x to close the file and enter y when prompted whether or not to save it. Now for the startup script:

root# cd /Library/LaunchDaemons
root# pico -w com.openerp.openerpserver.plist


Again you can just copy and paste the following text into the editor. This time there are no substitution that need to be made:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
<key>PY_USE_XMLPLUS</key>
<string></string>
<key>PATH</key>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/X11R6/bin:/opt/local/bin:/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin</string>
</dict>
<key>UserName</key>
<string>openerp</string>
<key>Label</key>
<string>com.openerp.openerpserver</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/openerp-server</string>
<string>-c</string>
<string>/Library/Server/OpenERP/Configuration/openerp-server.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceDescription</key>
<string>OpenERP Server</string>
<key>StandardOutPath</key>
<string>/Library/Server/OpenERP/Logs/OpenERP-Server.out</string>
<key>StandardErrorPath</key>
<string>/Library/Server/OpenERP/Logs/OpenERP-Server.err</string>
</dict>
</plist>


Step 9: At this point OpenERP Server should be fully installed and configured. You can now run the following command to start the server - no restart necessary.

root# launchctl load ./com.openerp.openerpserver.plist
root# exit
logout