網上有N種安裝方法,我都試過,沒有一個最后能成功,浪費了一下午的時間,終於搞定,
1.install Python
最新的Ubuntu操作系統是含有Python的,可以通過 Python --version 查看的:
lab@lab:~$ python version
Python 2.7.1+
2.install MySQL
使用最簡單的方法:sudo apt-get install mysql-server mysql-client
3.install Apache
繼續使用命令:sudo apt-get install apache2
4.install MySQLdb
sudo apt-get install python-mysqldb
5.install mod_python
sudo apt-get install libapache2-mod-python
6.install Django
到網站上下載: www.djangoproject.org Django-x.x.x.tar.gz
解壓:tar xzvf Django-1.2.1.tar.gz
安裝:sudo python install setup.py
7.測試Django 和 MySQLdb是否成功
在命令行:python
>>>import django
>>>import MySQLdb
如果沒有錯誤提示,則安裝成功!
>>>exit()
8.運行一個簡單程序不是用apache
lab@lab:~$ cd /var/www
lab@lab:~$sudo python /usr/local/bin/django-admin.py startproject server
lab@lab:~$ cd s*
lab@lab:~$ ls
可以看到在server 中多了幾個文件,不管他
lab@lab:~$ python manage.py runserver
出現如下提示:
0 errors foundDjango version 1.4 pre-alpha, using settings 'server.settings'Development server is running at http://127.0.0.1:8000/Quit the server with CONTROL-C.
證明一切OK!
打開瀏覽器:http://127.0.0.1:8000/server 出現如下畫面:
It worked!
Congratulations on your first Django-powered page.
django是個小的服務器,現在換沒有運行在apache2上了
9.配置apache2
command:cd /etc/apache2
command:sudo chmod 777 httpd.conf
command:gedit httpd.conf
添加:
LoadModule python_module /usr/local/lib/apache2/modules/mod_python.so<Location "/server/"> SetHandler python-program //這一句必須有,mod_python.so 在安裝mod_python時生成的,
PythonPath "['/var/www'] + sys.path" //這里不必添加server 目錄
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE server.settings //工程名server
PythonOption django.root /server
PythonDebug On
</Location>
重啟apache2 ,網上有很多種方法,直接重新開機是最實惠的。
10.打開瀏覽器:http://127.0.0.1:8000
出現:
It worked!
Congratulations on your first Django-powered page.
證明apache以配置完成
現在這個工程沒有任何程序
繼續work。