2012年3月19日 星期一

linux CentOS apache+django+Mysql

第一次用 linux 掛網站
遇到了許多的問題
花了一些時間了解和研究
終於還是成功了!!!

剛拿到了主機,大概先看了一下
系統是CentOS 6.0
已經有灌了
python2.6
mysql5
apache2

第一步當然是來把 django 灌起來吧!!!

wget http://www.djangoproject.com/download/1.3.1/tarball/ -----使用 wget 來 download
tar -zxvf  Django-1.3.1.tar.gz
cd Django-1.3.1
python setup.py install

djagno 安裝完畢
建一個新的專案來試試
Django version 1.3.1, using settings ‘test.settings’
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

ya可以動… 順利安裝
接著使用winSCP 上傳已製作好的網站…

再 manage.py runserver 一次
出現錯誤了 XD~
沒有 MySQLdb ....

重復上一個步驟

wget MySQLdb
tar -zxvf  MySQLdb.tar.gz
cd MySQLdb
python setup.py build
python install

裝完使用python
>> import  MySQLdb
ya 沒錯了

再 manage.py runserver 一次
出現錯誤了 XD~
沒有 PIL....

 重復上一個步驟

到了最後還發現還需要 libjpeg、libpng 才可以

安裝 libpng

wget ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.5.6.tar.gz
tar -xvzf libpng-1.5.6.tar.gz
cd libpng-1.5.6
./configure --prefix=/usr/local
make
sudo make install
 yum install libpng-devel

安裝 libjpeg

wget http://www.ijg.org/files/jpegsrc.v8d.tar.gz
tar -xvzf jpegsrc.v8d.tar.gz
cd jpeg-8c/
./configure --prefix=/usr/local
make
make install
yum install libjpeg-devel

wget PIL
tar -zxvf  PIL.tar.gz
cd PIL
python setup.py build
python install

裝完使用python
>> import PIL
>> import Image
>> import _imaging
ya 都沒錯了 ( 先前沒裝jpeg、png網站都掛好了,圖片上傳不上來,一直出現圖片格式錯誤的訊息,還以為是程式的問題,試了好天才知道,linux 需要 libjpeg ... )

再 manage.py runserver 一次
Django version 1.3.1, using settings ‘mysite.settings’
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

可以了最後就掛上apache ... 
需要 mod_wsgi

wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
tar -zxvf mod_wsgi-3.3.tar.gz
cd mod_wsgi-3.3
./configure --with-python=/usr/local/bin/python

錯誤:查google 需yum install httpd-devel

./configure --with-python=/usr/local/bin/python
make
make install

vim /etc/httpd/conf.d/wsgi.conf    ----- 新建wsgi.conf
加入 LoadModule wsgi_module modules/mod_wsgi.so   ------ 加入mod_wsgi.so

  WSGIScriptAlias /text "/var/www/html/text/text.wsgi"
  #WSGIScriptAlias / "/var/www/html/leisure/leisure.wsgi"
  WSGIScriptAlias /leisure "/var/www/html/leisure/leisure.wsgi" ---------使用wsgi路徑

  <Directory "/var/www/html/text">
        Order Deny,Allow
        Allow from all
  </Directory>

  <Directory "/var/www/html/leisure">
        Options +ExecCGI
        Order Deny,Allow
        Allow from all
  </Directory>



 /etc/init.d/httpd restart   ---------重新啟動apache

最後在 /var/www/html/leisure 設定 leisure.wsgi 就可以順利掛上了 ^^"

import os
import sys
from django.core.handlers.wsgi import WSGIHandler

sys.path.insert(0, 'python 路徑')
sys.path.insert(0, '/var/www/html/')
sys.path.insert(0, '/var/www/html/leisure')

os.chdir('/var/www/html/leisure')
os.environ['DJANGO_SETTINGS_MODULE'] = 'leisure.settings'

application = WSGIHandler()

終於完成 XD~



沒有留言:

張貼留言