Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save epicserve/311159 to your computer and use it in GitHub Desktop.
Save epicserve/311159 to your computer and use it in GitHub Desktop.
Django Enviroment Setup on Mac OSX 10.6.2 (Snow Leopard)

Django Enviroment Setup on Mac OSX 10.6.2 (Snow Leopard)

Install Homebrew

sudo mkdir /usr/local
sudo chown -R `whoami` /usr/local
curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local
brew install git
cd /usr/local
git init
git remote add origin git://github.com/mxcl/homebrew.git
git pull origin master

Install Mysql

brew install mysql

Run the mysql setup script that configures your root password. mysql_install_db mysql_secure_installation Change the root password? [Y/n] y Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y

If you have a dump file of previous databases you can install them this way.

mysql -u root -p mysql < /path/to/mysql-dump-file-all-databases.sql

Install Basic Python Packages

Install PIP for easy python package installation

sudo easy_install pip

Install MySQL-python

pip install http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz?use_mirror=cdnetworks-us-2

Install virtualenv so you can setup virtual python environments easily for each of your django projects.

pip install virtualenv

Install NGINX

Install nginx using homebrew.

brew install nginx

Backup the origional nginx config file.

cd /usr/local/etc/nginx
cp nginx.conf nginx.conf.orig

Replace /usr/local/etc/nginx/nginx.conf with the following.

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

	include /Users/oconnor/Sites/configs/nginx/sites-enabled/*;

}

Restart nginx

sudo nginx -s reload

Setup up Apache and PHP (optional)

Append the following to /private/etc/apache2/httpd.conf

# Include Virtual Hosts
NameVirtualHost *:8080
Include /Users/oconnor/Sites/configs/apache/sites-enabled/

Changed the port apache listens on to 8080. Find the line Listen 80 in the httpd.conf file and change the line to Listen 8080

Install php5 for the native OSX apache2 install. Got the follow steps from a tutorial I found doing a google search.

$  cd /usr/local/
$  git remote add boztek git://github.com/boztek/homebrew.git && git fetch boztek
$  git checkout boztek/php52 && git checkout -b working
$  git pull --rebase origin master
$  brew install php52 --with-mysql --with-apache
$  cd /usr/libexec/apache2
$  sudo mv libphp5.so libphp5.so.orig
$  sudo ln -s /usr/local/Cellar/php52/5.2.12/libexec/apache2/libphp5.so

Uncomment the following line in your httpd.conf

# LoadModule php5_module        libexec/apache2/libphp5.so

Restart Apache

$  sudo apachectl restart

Setup phpMyAdmin

  1. Download phpMyAdmin from http://www.phpmyadmin.net.

  2. Extract the tar gzipped file into the /Users/oconnor/Sites/phpmyadmin directory.

  3. Add the following to your sites-available directory and then symlink the file in your sites-enabled directory.

    phpMyAdmin default Apache configuration

    Alias /phpmyadmin /Users/oconnor/Sites/phpmyadmin

    <Directory /Users/oconnor/Sites/phpmyadmin> Options FollowSymLinks DirectoryIndex index.php

         <IfModule mod_php5.c>
                 AddType application/x-httpd-php .php
    
                 php_flag magic_quotes_gpc Off
                 php_flag track_vars On
                 php_flag register_globals Off
                 php_value include_path .
         </IfModule>
    

    Authorize for setup

    <Directory /Users/oconnor/Sites/phpmyadmin/setup> AuthType Basic AuthName "phpMyAdmin Setup" AuthUserFile /etc/phpmyadmin/htpasswd.setup Require valid-user

    Disallow web access to directories that don't need it

    <Directory /Users/oconnor/Sites/phpmyadmin/libraries> Order Deny,Allow Deny from All <Directory /Users/oconnor/Sites/phpmyadmin/setup/lib> Order Deny,Allow Deny from All

  4. Import phpmyadmin/scripts/create_tables.sql into your MySQL database.

  5. Copy phpmyadmin/config.sample.inc.php to phpmyadmin/config.inc.php

  6. Edit config.inc.php and add a 20 character string for the $cfg['blowfish_secret'] variable and uncomment all the variables under the /* Advanced phpMyAdmin features */ comment line.

  7. Restart apache, sudo apachectl restart

  8. Load up phpMyAdmin in your browser http://localhost/phpmyadmin

@nguyenlocduy
Copy link

Nice, just one correction: In the Apache Installation Part, the 'Listen' port should be 8080.

@epicserve
Copy link
Author

Thanks for pointing out the error. I made the correction. :)

@rdjs
Copy link

rdjs commented Sep 20, 2011

Just tried this....

$ brew install pip
Error: No available formula for pip
Install pip with easy_install:
easy_install pip

@epicserve
Copy link
Author

@rdjs, maybe brew no longer has pip formula. Did you try using easy_install like it says in the error message?

@rdjs
Copy link

rdjs commented Sep 20, 2011

Sorry, it looks like half my comment got lost when I submitted it...

I used easy_install and it worked fine, thought you might like to update the gist. Thanks!

@epicserve
Copy link
Author

@rdjs, made the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment