Monday, 10 February 2014

Setup Maverick apache with django and Postgres

I will detail the process soon..!

Ok here is the steps that I found to work on Feb 2014. It takes me a few weeks to get it.

I have tried my 2 Mac
- Mac OS X 10.8.5 Mountain Lion
- Mac OS X 10.9 Maverick

Step 1. Install PostgreSQL 9.3

download postgresql-9.3.2-2-osx and install. This is first and easiest part. Then edit your python project setting in your python mysite file

    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', #django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'postgres',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'postgres',
        'PASSWORD': 'xxx',
        'HOST': '',                      # Empty for localhost through domain sockets or '' for localhost through TCP.
        'PORT': '5432',                      # Set to empty string for default.

Step 2. Install adapter psycopy2 2.5.2 for PostgreSQl to Python

cd psycopg2-2.5.2
python build
python install
sudo ln -s /Library/PostgreSQL/9.3/lib/libssl.1.0.0.dylib /usr/lib
sudo ln -s /Library/PostgreSQL/9.3/lib/libcrypto.1.0.0.dylib /usr/lib

Step 3. Install mod_wsgi-3.4 It is a module for apache to run python. I think OS X server has built in. 

Goto terminal and cd to the mod_wsgi-3.4 directory

And type in ./configure
and then type in 

for Maverick:
$ sudo ln -s /Applications/ /Applications/

for mountain lion:
$ sudo ln -s /Applications/ /Applications/

Then use finder and open the file makefile in mod_wsgi-3.4 directory. Edit the CPPFLAGS parameter by inserting the below 

-I/Applications/ -I/Applications/ -I/Applications/ -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -DENABLE_DTRACE -DMACOSX -DNDEBUG -DNDEBUG -DENABLE_DTRACE 
Insert right after the "=" character. For mountain lion, replace 10.9 above with 10.8


CPPFLAGS =  -I/Applications/ -I/Applications/ -I/Applications/ -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -DENABLE_DTRACE -DMACOSX -DNDEBUG -DNDEBUG -DENABLE_DTRACE 

Lastly, type in 
make install

And should be created. It is used in the next step. 

4. Configure Apache config file

- Goto terminal and edit the config file:
sudo pico /etc/apache2/httpd.conf

- Scroll down to load Module part and add wsgi
LoadModule wsgi_module libexec/apache2/

WSGIScriptAlias / /Users/yongchong/Sites/mysite/mysite/
WSGIPythonPath /Users/yongchong/Sites/mysite

<Directory "/Users/yongchong/Sites/mysite/mysite">
Order deny,allow
Allow from all


<Directory "/Users/yongchong/Sites/mysite">
    # /Library/WebServer/Documents">

exit and save config file

Then add permission here for apache at terminal
chmod +x /Users/yongchong/Sites

So the combination of apache + python + postgresql is really solid. It never fail.. 2 months and running!

And here you go!


  1. It's cool! Thanks for the detailed description. I only had small issues with Configure Apache config file (I could not edit). I have been working in the field of software development and currently use an application from ios app development company. I would like to learn how to make such an application. This is certainly great!

  2. It is really an interesting and informative sharing. Just keep up the good work.

    Mobile Phone App Development

  3. we are dreadfully thankful to all of your team for sharing such motivating information.
    MObile App Development ::: iOS App Development