Setup Python, MySQL, MySQL-python and SVN on MAC OS X 10.6
Categories: Mac OS X, others, Python on Oct.11, 2009
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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <true/> <key>Label</key> <string>com.mysql.mysqld</string> <key>Program</key> <string>/usr/local/mysql/bin/mysqld_safe</string> <key>RunAtLoad</key> <true/> <key>UserName</key> <string>mysql</string> <key>WorkingDirectory</key> <string>/usr/local/mysql</string> </dict> </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 2 3 4 5 6 7 8 9 10 11 12 13 | #ifndef uint #define uint unsigned int #endif Change the following: uint port = MYSQL_PORT; uint client_flag = 0; to unsigned int port = MYSQL_PORT; 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 2 3 | import os os.environ['PYTHON_EGG_CACHE'] = '/Users/you_user_name/Sites/Temp' 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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | NameVirtualHost *:80 <VirtualHost *:80> ServerName "you_server_name" DocumentRoot "/Users/pyromann/Sites/my_project" ErrorLog "/private/var/log/apache2/my_project-error_log" CustomLog "/private/var/log/apache2/my_project-access_log" common <Directory "/Users/pyromann/Sites/my_project"> Options FollowSymLinks MultiViews Includes AllowOverride All Order allow,deny Allow from all </Directory> <Location "/"> SetHandler python-program SetEnv DJANGO_SETTINGS_MODULE my_project.settings PythonHandler django.core.handlers.modpython PythonPath "sys.path + ['/Users/your_user_name/Sites/']" PythonOption django.root /my_project PythonDebug On PythonInterpreter my_project </Location> <Location "/media"> SetHandler None </Location> <LocationMatch ".(jpg|gif|png)$"> SetHandler None </LocationMatch> </VirtualHost> <VirtualHost *:80> ServerName "mysqladmin.loc" ServerAlias "www.mysqladmin.loc" DocumentRoot "/Users/your_user_name/Sites/mysqladmin" </VirtualHost> <VirtualHost *:80> ServerName "svn.loc" ServerAlias "www.svn.loc" DocumentRoot "/Users/your_user_name/Sites/websvn" </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:
Similar posts:


Оставить отзыв