今儿开始在linux下安装django,为了很好的运行程序,我需要apache的支持,不多说拉,上步骤:
前提:
apache : httpd-2.2.17.tar.gz
mod_python : mod_python-3.3.1.tgz
Django : Django-1.2.4.tar.gz
python : 2.5.4
另:这里不提及python 的安装步骤,需要的同学请搜索我的相关文章哈
开始了
一。安装 apache
#tar xvfz httpd-2.2.17.tar.gz
#cd httpd-2.2.17
#./configure --prefix=/usr/local/apache --enable-so --enable-mods-shared=all --enable-cgi --enable-rewrite --enable-deflate --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=worker
#make
#make install
整个过程apache安装完成,但是有个问题,我在configure 时遇到点问题,大概是无法bind apr 及apr-util ,解决:
下载:apr-1.2.9.tar.gz和apr-util-1.2.8.tar.gz
#tar xzvf apr-1.2.9.tar.gz
#cd apr-1.2.9
#./configure --prefix=/usr/local/apr
#make
#make install
#tar xzvf apr-util-1.2.8.tar.gz
#cd apr-util-1.2.8
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make
#make install
解决后重新configure 就哦啦。
二。modpython的安装
到www.modpython.org 下载相关包
#tar -zxvf ./mod_python-3.3.1.tgz
#cd mod_python-3.3.1
# ./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/bin/python2.5
注意:configure 后面的参数需要你指定apache的apxs地址和python位置
# make
我这里出错了,没出错的同学跳过哈
connobject.c:142: error: request for member `next' in something not a structure or union
apxs:Error: Command failed with rc=65536
.
make[1]: *** [mod_python.so] ?? 1
make[1]: Leaving directory `/home/jizhong/python/python/mod_python-3.3.1/src'
make: *** [do_dso] ?? 2
查了资料,决定修改: src/connobject.c
//!(b == APR_BRIGADE_SENTINEL(b) ||
!(b == APR_BRIGADE_SENTINEL(bb) ||
继续:
#make install
之后,mod_python 会在 /usr/local/apache/modules 增加 mod_python.so 文件并在 /usr/local/python/lib/python2.5/site-packages 中添加 mod_python 包
然后修改:/usr/local/apache/conf/httpd.conf
添加:
LoadModule python_module modules/mod_python.so
四。安装django
#tar xzvf Django-1.2.4.tar.gz
#cd Django-1.2.4
#sudo python setup.py install
# mkdir /htdocs
# cd /htdocs
# /home/jizhong/python/python/Django-1.2.4/django/bin/django-admin.py startproject myproject
# cd myproject
# python manager.py runserver 0.0.0.0:8000
访问: http://192.168.100.222:8000/ 当然了,我的linux战斗机在局域网内哈,就这个IP。
“IT WORKS”没?必须地是把!恭喜你快成功了。
五。APACHE运行django程序:
修改配置文件 httpd.conf
去掉#Include conf/extra/httpd-vhosts.conf中的"#"
去掉#ServerName 127.0.0.1 中的"#"
修改extract/httpd-vhost.conf:
添加一个VirtualHost :
<VirtualHost *:80>
<Location "/">
SetHandler python-program
PythonPath "['/home/jizhong/htdocs'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myproject.settings
PythonAutoReload Off
PythonDebug On
</Location>
</VirtualHost>
保存,退出,重启APACHE:
apache命令:
进入/usr/local/apache/bin
开启:
./httpd -k start
关闭:
./httpd -k stop
重启后访问:http://192.168.100.222:80,“IT WORKS”没?还是必须地是把!
如果你也看见了,那就是有点小小成就感了吧,喝口水,听听音乐,然后抓紧搞起你的程序吧!