Skip to main content

How to install python and configure django on a CentOS 6.7 Linux server with CPanel?

I recently had a chance to play with CentOS 6.7 server. My task was to re-install(reconfigure) run a Django site on it. Actually it was done by my around 2 years before. Then some system admin guy updated the system (especially PHP related stuff), and essentially he screwed up my (ie. I worked tm.) django website. I had lost the track on installing those things. So I would like to share my experience on reaching the point.

First of all I tried to locate the apache config file. My initial thoughts were about this file.
I roamed here and there, to get some idea about the system.Here are my commands which I use these sort of tasks.
which httpd
which apache
which apache2
type httpd
locate apache.conf
locate httpd.conf
whatis httpd 
 Sure, You should use man pages to get more info of these commands like which,type and locate. Try `man man` to know what man is.

Anyway, I got some ideas regarding where the conf files lies, especially with the help of locate command

I also had used below command to find CentOS version.
cat /etc/redhat-release

Since, I found some more useful commands from the internet those helped me to get an hint to the problem.  The most useful one in my case was
/etc/init.d/httpd status
This command gave me the hint, the wsgi module was not in the new apache.


You should use either locate, whatis, type, which etc to get relevant info.
Using file would be nice to check the file exists or not. See
file /path/to/file

Install Python

Now, I checked version of python. It is 2.6.6 in that server. I decided to install Python-2.7 as the site was developed against it.

I did refer this article to get an idea

In my case these were the relevant parts.
# install essential dependencies
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel  sqlite-devel \
 readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

# Python 2.7.6:
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
# altinstall make python available on as python2.7,
# leaving existing python,python2,python2.6
# so it won't break anything existing
make && make altinstall

# Install pip
easy_install-2.7 pip

# It's a good idea to install virtualenvwrapper
pip2.7 install virtualenvwrapper

If you are interested in virtualenvwrapper, you must read their docs. It's an excellent doc. See

Install WSGI

 First of all, I refered this link,
cd ~
gzip -dc mod_wsgi-3.2.tar.gz | tar xf -
cd mod_wsgi-3.2
./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/bin/python2.7
make && make install 

Include the configuration file

After compiling the module, 
I was given the path to where it was located (/usr/lib/httpd/modules/

I logged in to WHM
WHM -> Server Configuration -> Apache Setup -> Include Editor
to add the following line to load the module
LoadModule wsgi_module /usr/lib/httpd/modules/

Connecting django app

In order to connect django app you have to create an apache conf file in 

mkdir -p /usr/local/apache/conf/userdata/std/2/fcabi/

The above path may not be same for you. Try ls /usr/local/apache/conf/userdata/std/. It may be 2 or something like 2_2. In my case it was 2_2.

So I used some thing like this
mkdir -p /usr/local/apache/conf/userdata/std/2_2/username/>/
In above username was the one I created with CPanel for this site and was the address of my site.

Now, create config file
vi /usr/local/apache/conf/userdata/std/2_2/myuser/

Alias /media/ /srv/Test/app/mysite/media/
Alias /static/ /srv/Test/app/mysite/static/
Alias /robots.txt /srv/Test/app/mysite/robots.txt
Alias /favicon.ico /srv/Test/app/mysite/static/images/favicon.ico

CustomLog "|/usr/sbin/rotatelogs /srv/Test/logs/access.log.%Y%m%d-%H%M%S 5M" combined
ErrorLog "|/usr/sbin/rotatelogs /srv/Test/logs/error.log.%Y%m%d-%H%M%S 5M"
LogLevel warn

WSGIDaemonProcess user=myuser group=mygroup
WSGIScriptAlias / /srv/Test/app/conf/apache/mysite.wsgi

<Directory /srv/Test/app/mysite/media>
Order deny,allow
Allow from all

<Directory /srv/Test/app/mysite/static>
Order deny,allow
Allow from all

<Directory /srv/Test/app/conf/apache>
Order deny,allow
Allow from all

On reading through above you get the idea of apache configuration. We specify various things like wsgi file, static directory, media directory etc. You must replace them with your own.

Now create the wsgi file. In my case wsgi was in

In my case, the wsgi file is almost the same as the one provided by django
ie. the file in mysite/ (in settings folder).

But a little modification to include virtualenv settings.

vi /srv/Test/app/conf/apache/mysite.wsgi
import os
import sys

# Activate venv
activate_this = '/home/{}/.virtualenvs/mysiteenv/bin/'.format('myuser')
execfile(activate_this, dict(__file__=activate_this))

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

Look at the two lines after # Activate venv those lines determine the venv.
Since I use virtualenvwrapper.
I usually activate virtualenv  by either
workon mysiteenv
source env/bin/activate

Then I type which python which resulsts some thing like ~/.virtualenvs/mysiteenv/python. Now I replace python with So ~/.virtualenvs/mysiteenv/

Rebuild the config file and restart apache

It is nice check for syntax errors in apache config file first.
/usr/sbin/apachectl configtest
/usr/sbin/apachectl -t
#or may be even
httpd -t
httpd configtest

You can use following commands to rebuild the configuration file.

/usr/sbin/apachectl restart

That's it. I have provided enough information, links and debugging tips. Hope you enjoy it.

Popular posts from this blog

How to run android apk in your Google Chrome browser with Google's ARC

Google's plan on merging android with ChromeOS is on the way.

What you need is

1. Google Chrome 41+. It works on PC,Linux,Mac.
Or Chromebook on Chrome Version 41+.
2. You apk files to run
3. The ARC Welder app

1. To get chrome

In ubuntu/debian you can install *.deb file by

sudo dpkg -i google*.deb
In fedora/ RedHat Linux 

rpm -ivh google*.rpm
2. To get your apk files
Either use
Or some sites like

3. Go to The ARC Welder app.And install it from Google Chrome browser.

I used this game (2048) for testing.

This is the result i got.

NB:- There is a limitation. It's is only possible to do one app at time

I tested on Ubuntu 14.04 and Fedora 21.


AndroVMPlayer : Improved Android Virtual Machine

AndroiVMPlayer is built on on VirtualBox it provides a performance increase to our installed Android (AndroVM's built in Android Virtual Machine, see Official Page )

What you want to do is just install Android as i mentioned in the post (AndroVM).

Just extract the zip file into a place where you like. (Zip 32-bit, Zip 64-bit Download appropriate version for your operating System).

Right click on AndroiVMPlayer.exe , then from the menu, Send To > Desktop (Create Shortcut) .

Now on Desktop there will be a icon

 Running the AndroVMPlayer Now right click on it and Run it as Admin

WhatsApp on PC: Installation

Hi Friends,

This post will show you how to install WhatsApp on PC. And how to import your contacts from phone or other devices, how to add your photos etc willl be on another Post.

It can be divided into two parts.


In order to install WhatsApp on PC you have to download some files first.

Install virtualbox by following the link.


Then you have to restart the your computer.

Download the pre-configured Virtual Machine (You may visit AndroVM Page to know more )


After downloading the AndroVM you can double clickon it . androVM_vbox86tp_4.1.1_r6.1-20130222-gapps-houdini-flash.ova
(If your VirtualBox is installed correctly your file should be shown with an orange colored icon).

Now press Import Button

Thus you are done the installation. Now you can press the Start button in the VirtualBox. And see your virtual Android machine.(Or you can import from VirtualBox by File>Import Appliance... Then select the file above.)

Now you should …