Mac Os X + Python 2.6.1+ PIL + apache2.2 +mod_python + MySQL + MySQLdb +php5+ phpMyAdmin + SVN server +WebSVN

OS: Mac OS X 10.6.1 Snow Leopard
XCode:The latest Xcode Tools
Python: Python 2.6.1 64-bit (Snow Leopard default)

Projects will be located in ~/Sites, so change permissions:
add read permission for everyone on ~/Sites

Setup django

1. mkdir ~/sources
2. cd ~/sources
3. svn co http://code.djangoproject.com/svn/django/trunk/ django
4. cd django
5. sudo python setup.py install

Apache:
We will use default 10.6 apache2.2

Setup mod_python:
1. mkdir ~/sources/mod_python
2. cd ~/sources/mod_python
3. svn co http://svn.apache.org/repos/asf/quetzalcoatl/mod_python/trunk mod_python-trunk
4. cd mod_python-trunk
5. ./configure –with-apxs=/usr/sbin/apxs
6. make
7. sudo make install


Setup MySQL — Download 64bit!!!
1. nano ~/.profile
2. export PATH=”/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH”
3. source ~/.profile
4. Download MySQL 5.1.39 sourcse and place it into ~/sources
5. tar xzvf mysql-5.1.39.tar.gz
6. cd mysql-5.1.39

7. ./configure –prefix=/usr/local/mysql –with-extra-charsets=complex \
–enable-thread-safe-client –enable-local-infile –enable-shared \
–with-plugins=innobase
8. make
9. sudo make install
10. cd /usr/local/mysql
11. sudo ./bin/mysql_install_db –user=mysql
12. sudo chown -R mysql ./var
13. cd ..
14. open TexEdit, switch to plain text
copy-paste:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3. <plist version="1.0">
  4. <dict>
  5.     <key>KeepAlive</key>
  6.     <true/>
  7.     <key>Label</key>
  8.     <string>com.mysql.mysqld</string>
  9.     <key>Program</key>
  10.     <string>/usr/local/mysql/bin/mysqld_safe</string>
  11.     <key>RunAtLoad</key>
  12.     <true/>
  13.     <key>UserName</key>
  14.     <string>mysql</string>
  15.     <key>WorkingDirectory</key>
  16.     <string>/usr/local/mysql</string>
  17. </dict>
  18. </plist>

save as ~/sources/com.mysql.mysqld.plist
close TexEdit

15. sudo mv ~/sources/com.mysql.mysqld.plist /Library/LaunchDaemons
16. sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plist
17. sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
18. mysqladmin -u root password NEW_PASSWORD

Setup MySQL for Python adapter

1. Download the latest MySQL for Python adapter from SourceForge(http://sourceforge.net/project/showfiles.php?group_id=22307) and copy to ~/sources
2. cd ~/sources
3. tar xzvf MySQL-python-1.2.2.tar.gz
4. cd ./MySQL-python-1.2.2
5. Inside the folder, clean the package by typing
6. sudo python setup.py clean
7. In the same folder, edit _mysql.c using your favourite text-editor
8. Remove the following lines (37-39):

  1. #ifndef uint
  2.         #define uint unsigned int
  3.         #endif
  4.  
  5.        Change the following:
  6.  
  7.        uint port = MYSQL_PORT;
  8.        uint client_flag = 0;
  9.  
  10.        to
  11.  
  12.        unsigned int port = MYSQL_PORT;
  13.        unsigned int client_flag = 0;

9. Create a symbolic link under lib to point to a sub-directory called mysql. This is where it looks for during compilation.
10.sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql
11. Edit the setup_posix.py and change the following
mysql_config.path = “mysql_config”
to
mysql_config.path = “/usr/local/mysql/bin/mysql_config”
12.In the same directory, rebuild your package (ignore the warnings that comes with it)

13. sudo python setup.py build

Install the package and you are done.

14. sudo python setup.py install

Test if it’s working. It works if you can import MySQLdb.

python
>>> import MySQLdb

SVN
We will be using build in svn + WebSvn for repo browsing
1. mkdir ~/svn
2 cd ~
3.chown -R _www svn
4. svnadmin create –fs-type fsfs myrepo-1
5. donwload latest WebSVN
6. Unpack in into ~/Sites
7. rename to websvn
8. chmod 0700 ~/Sites/websvn/cache
9. rename ~/Sites/websvn/include/distconfig.php to ~/Sites/websvn/include/config.php
10. edit ~/Sites/websvn/include/config.php:
find and uncomment
$config->useTreeIndex(true); // Tree index, open by default
$config->addInlineMimeType(”text/plain”);
$config->hideRSS();
$config->parentPath(’path/to/yours/svn’);

Starting project
1. cd ~/Sites
2. mkdir Temp
3. chmod 0700 ~/Sites/Temp
4. django-admin.py start project my_project
5. nano apache_settings.py
6. add lines:

  1. import os
  2.       os.environ['PYTHON_EGG_CACHE'] = '/Users/you_user_name/Sites/Temp'
  3.    close apache_settings.py

Configure Apache:
sudo nano /etc/apache2/httpd.conf
Add lines:
LoadModule python_module libexec/apache2/mod_python.so
LoadModule php5_module libexec/apache2/libphp5.so #for WebSvn and phpMyAdmin
Uncomment:
Include /private/etc/apache2/extra/httpd-vhosts.conf
Add line:
PythonImport /Users/you_user_name/Sites/my_project/apache_settings.py my_project
save and exit httpd.conf

Configure VirtualHosts:
sudo nano /etc/apache2/extra/httpd-vhosts.conf
remove all lines
add

  1. NameVirtualHost *:80
  2.    
  3. <VirtualHost *:80>
  4.     ServerName "you_server_name"
  5.     DocumentRoot "/Users/pyromann/Sites/my_project"
  6.     ErrorLog     "/private/var/log/apache2/my_project-error_log"
  7.     CustomLog   "/private/var/log/apache2/my_project-access_log" common
  8.     <Directory "/Users/pyromann/Sites/my_project">
  9.         Options FollowSymLinks MultiViews Includes
  10.         AllowOverride All
  11.         Order allow,deny
  12.         Allow from all
  13.     </Directory>
  14.  
  15.     <Location "/">
  16.         SetHandler python-program
  17.         SetEnv  DJANGO_SETTINGS_MODULE my_project.settings
  18.         PythonHandler django.core.handlers.modpython
  19.         PythonPath "sys.path + ['/Users/your_user_name/Sites/']"
  20.         PythonOption django.root /my_project
  21.         PythonDebug On
  22.         PythonInterpreter my_project
  23.     </Location>
  24.  
  25.     <Location "/media">
  26.         SetHandler None
  27.     </Location>
  28.  
  29.     <LocationMatch ".(jpg|gif|png)$">
  30.         SetHandler None
  31.     </LocationMatch>
  32.  
  33. </VirtualHost>
  34.  
  35. <VirtualHost *:80>
  36.     ServerName "mysqladmin.loc"
  37.     ServerAlias "www.mysqladmin.loc"
  38.     DocumentRoot "/Users/your_user_name/Sites/mysqladmin"
  39. </VirtualHost>
  40.  
  41.  
  42. <VirtualHost *:80>
  43.     ServerName "svn.loc"
  44.     ServerAlias "www.svn.loc"
  45.     DocumentRoot "/Users/your_user_name/Sites/websvn"
  46. </VirtualHost>

Setup hosts
sudo nano /etc/hosts
add line:
127.0.0.1 your_server_name svn.loc mysqladmin.loc

restart apache
sudo apachectl restart
http://svn.loc – yours svn
http://mysqladmin.loc – phpMyAdmin
http://your_server_name – yours django project

setup PIL
Download lates sources
Place it to ~/sources
tar xzfv Imaging-1.1.6.tar
cd Imaging-1.1.6
python setup.py build
sudo python setup.py install

Source:

How to setup django development environment in Mac OS X 10.6 Snow Leopard