This blog simply records all I've learned for IT knowledge.

Wednesday, December 9, 2009

install django in centos 5

# rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
# yum -y install lighttpd lighttpd-fastcgi mysql-server
# /etc/init.d/lighttpd start
change port from 80 to 8080 if needed:
# vi /etc/lighttpd/lighttpd.conf


- start lighttpd when system starts up:

/sbin/chkconfig --level 235 lighttpd on
/etc/init.d/lighttpd start

- install postgresql server
yum install postgresql postgresql-server
yum install postgresql-python python-psycopg2

edited the /etc/yum.repos.d/CentOS-Base.repo and changed the gpgcheck=1 to gpgcheck=0
if you met some warning messages.

Verify the installation

>>> import psycopg2
>>> psycopg2.apilevel
'2.0'


- setup postgresql user:
/usr/sbin/adduser postgres
mkdir /home/postgres
cd /home/postgres
chown -R postgres postgres


- setup firewall
allow http(s) and other port (like 8080, 5432(postgre port))

vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
service iptables restart

- install mysql
yum install mysql*
yum install MySQL*

- install MySQLdb
yum install python-devel*
yum groupinstall "MySQL Database"

- install gcc (needed by PIL)
yum install gcc

- install libjpeg

wget http://www.ijg.org/files/jpegsrc.v7.tar.gz
tar zxvf *.tar.gz
cd jpeg-6b/
./configure
make
sudo make install-lib

- install python-imaging
yum install python-imaging

- install PIL
wget http://effbot.org/downloads/Imaging-1.1.6.tar.gz
tar zxvf Image*.gz
cd Image*
python setup.py install

if you have such errors:
_imagingtk.c:20:16: error: tk.h: No such file or directory
install tcl-devel and tk-devel by yum


if you have issue when uploading image, check

/usr/lib/python2.4/site-packages/django/forms/fields.py

- install django

- upgrade MySQLdb
+ install easy_install: yum install python-setuptools
+ download the source: http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz?use_mirror=softlayer
+ install the packeg:
* export PYTHON_EGG_CACHE=/var/cache/python-eggs
* mkdir /var/cache/python-eggs
* chmod 777 /var/cache/python-eggs
* python setup.py build
* python setup.py install


- initialization of mysql
+ mysqladmin -u root password "newpassword"
+ mysql -u root -p
+ mysql>create user 'alpha'@'localhost' identified by 'some_passwd';
+ mysql>grant all privileges on alpha.* to 'alpha'@'localhost' with grant option;



- install python-yaml
+ yum install python-yaml

- vi /etc/httpd/conf.d/python.conf


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
SetEnv PYTHON_EGG_CACHE /var/cache/python-eggs
PythonOption django.root /alpha
PythonDebug On
PythonPath "['/var/www', '/var/www/alpha'] + sys.path"
PythonInterpreter alpha


or virtual host


ServerName xxx.com
ServerAdmin xxx.com

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
SetEnv PYTHON_EGG_CACHE /var/cache/python-eggs
PythonOption django.root /fornia
PythonDebug On
PythonPath "['/var/www', '/var/www/fornia'] + sys.path"
PythonInterpreter fornia





- if not be able to connect to DB, try to disable SELinux



matplotlib in django: http://bitsofpy.blogspot.com/2009/07/matplotlib-in-django.html




- mysql & Chinese support
1. change /etc/my.conf like:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
default-character-set=utf8
default-collation=utf8_general_ci

2. set charset in the database

alter database da_name character set utf8

3. "show character set" to make sure.


- change VPS localtime:
ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime