Wednesday, August 10, 2011

OpenCV with Python on WSGI on CentOS with Plesk10

Well it all comes together rather nicely...
My old-ish saying that "If I can make it work on OSX I'll make it work anywhere!" proved true again!
In the past I managed to make Python+WSGI+OpenCV work on Snow Leopard with MacPorts. You can find the articles related to that on this very blog. It was quite a ride.
But the final goal was to get it working on a bad ass CentOS hosting server we run at the company. The problem was it came with Plesk 10. Now I won't go into a rant about Plesk. Suffice to say it's 10 because the update of 9 to 10 went horribly wrong and ended with a server move :-D
Luckily the guys at Rackspace I'm such a big fan of made the IUS Repos available for the very purpose of providing "A better way to upgrade RHEL". And that it is.

I did not update PHP using IUS because amazingly Parallels came up with a way to do that and now you can have 5.3 rather easy and not break Plesk. But Python 2.6 on CentOS is a different story.
Suffice to say that following the IUS articles I manage to have Python 2.6 and mod_wsgi quickly and painlessly running on the box.

The big problem was compiling OpenCV2 and after yumming all the required packages like python26-numpy, python26-distribute, a compiler, some image libs and make as per the OpenCV docs, the magical command was:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=YES -D PYTHON_EXECUTABLE=/usr/bin/python26 -D CMAKE_MAKE_PROGRAM=/usr/bin/make ..
After that I had to copy the cv.so and cv2.so into the python26 site-packages because the install put them into the dist-packages folder. Then I yummed python-setuptools and used easy_install-26 to install Werkzeug. Jaaaa!

The only remained glitch was the mod_wsgi setup with Plesk.
Plesk comes with mod_python and it acts like that's a major achievement. I simply commented everything in /etc/httpd/conf.d/python.conf and added a vhost.conf file in the mydomain.com/conf Plesk domain folder. In there I pasted the basic WSGI setup including explicitly specifying the user I want the process to run under and that is the user you defined in Plesk at domain creation and who owns that folder.
The setup looks something like this:

WSGIDaemonProcess mydomain.com home=/var/www/vhosts/mydomain.com/httpdocs user=YOUR_DEFINED_PLESK_USER processes=2 threads=5
WSGIScriptAlias / "/var/www/vhosts/mydomain.com/httpdocs/application.wsgi"

<Directory "/var/www/vhosts/mydomain.com/httpdocs">
	WSGIProcessGroup mydomain.com
	WSGIApplicationGroup %{GLOBAL}
	Order deny,allow
	Allow from all
</Directory>

After nailing the Plesk extra config file with a
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain mydomain.com
all was up and running.

And it sure is great when that happens ;-)

1 Comments:

Anonymous Anonymous said...

Thanks man, this helped alot :)
Had to specify python-path=/path/to/httpdocs as option to WSGIDaemonProcess for local imports and file access to work properly.

11:28 PM, April 10, 2012  

Post a Comment

Links to this post:

Create a Link

<< Home