Python websocket on Centos 5.x

I am currently running a VPS as a playground and my SVN repo and decided to go ahead and set up a websockets server as well. This proved to be a little tricky but eventually got it working. Note that installing the default mod_python will give you version 3.2.8. pywebsocket requires Python 2.3 and up and mod_python 3.3 and up. Heres how I set up my server:

Start off by enabling EPEL if you haven’t done so already:
rpm -ivh

Next, install Python 2.6
yum install python26

Then install mod_python 2.6
yum install python26-mod_python

I chose to run it under apache so next you need to edit your httpd.conf file.

LoadModule python_module modules/
LoadModule python_module libexec/apache2/

AddHandler mod_python .py

Please note the path to Python as well as the PythonOption path. I put my websock handlers in the var folder but you can put it anywhere just make sure to create the document root for those websocket handlers.

After this you can restart your server:
/etc/init.d/httpd restart

Once restarted you can then download the pywebsocket repository

svn checkout pywebsocket-read-only

Then install:

cd pywebsocket-read-only
cd src

python build
sudo python install

Next you will need to also add this to httpd.conf:

PythonPath "sys.path+['/usr/lib/python2.6/site-packages']"
PythonOption mod_pywebsocket.handler_root /var/websock_handlers
PythonHeaderParserHandler mod_pywebsocket.headerparserhandler
PythonOption mod_pywebsocket.allow_draft75 On

Then all you have to do is restart apache, create the repository from above (in my example it is /var/websock_handlers). Then cp over from the /src/examples directory. Finally all you need to run is ./ and you should receive some output similar to:

Send: Hello
Recv: Hello
Send: 日本
Recv: 日本
Send: Goodbye
Recv: Goodbye