Note: These instructions are for root owners of WHM/cPanel systems, not end users.
If you want to run Django sites on a cPanel server, you’ll probably want to use the mod_wsgi Apache module. There are plenty of instructions out there on compiling mod_wsgi, but if you create it outside of the cPanel system,
mod_wsgi.so will vanish each time you run easy_apache to upgrade your apache and php.
The key is to install this mod_wsgi for cPanel module. But before you go there, you’re going to want a more recent version of Python installed, since RedHat and CentOS still ship with Python 2.4, which will be deprecated by Django soon. However, you can’t overwrite the system-provided Python because yum and Mailman depend on it.
Download Python 2.7 (or whatever the latest is) into
/usr/local/src. It’s critical that you build Python with shared libraries enabled, since mod_wsgi will be wanting to use them. So unpack the Python archive and cd into it, then:
You’ll get a new build of python in
/usr/local/bin, without disrupting the native version in
/usr/bin. Any user wanting python2.7 to be their default can add this to their
You’ll also get new libpython shared objects in
/usr/local/lib. When you go to build mod_wsgi, easy_apache will need to look for python libs in that location. I found that copying the libs into standard library locations such as /lib and /usr/lib as suggested here didn’t do the trick. What did work was to add a system configuration file pointing to the new libs. Do this:
echo "/usr/local/lib/" > python27.conf
Now you’re ready to build mod_wsgi through easy_apache. Download custom_opt_mod-mod_wsgi.tar.gz from this ticket at google code and run:
tar -C /var/cpanel/easy/apache/custom_opt_mods -xzf custom_opt_mod-mod_wsgi.tar.gz
That unpacks the module into the right location so that easy_apache will find it and present it as a build option. Run easy_apache as usual (either via script or through WHM) and select the mod_wsgi option. When complete, you’ll find
mod_wsgi.so along with all your other modules in
/usr/local/apache/modules. The best part is, this will now become part of the default easy_apache build process, so Django sites won’t break when you rebuild apache+php in the future.
Many thanks to challgren for creating the module and to Graham Dumpleton for all of his mod_wsgi evangelism and support.