前一篇文章写的在APACHE安装MOD_PYTHON的经过,其实挺简单,就是版本不兼容的问题.这次我大概说下部署DJANGO的过程.
先修改APACHE配置文件,使其加载mod_python模块
LoadModule python_module libexec/mod_python.so
运行命令查看
bin/httpd -M可以看到
python_module (shared)
Syntax OK
说明apache已经成功加载mod_python.
下面我说下我的实际的环境和项目情况:
/infoware/xx/web是django程序目录
/infoware/_conf/xx/是控制django的程序还有一些配置(有些配置变量没有写在settings),这一步可以不需要,因为大多数人会直接配置settings文件的.我是在虚拟主机上操作.
–CENTOS5.2+APACHE2.2.11+PYTHON 2.4.3+MOD_PYTHON3.3.1+DJANGO 0.96
下面是apache配置文件
—————————————————-
<VirtualHost *:80>
ServerAdmin webmaster@xxcom
DocumentRoot “/infoware/xx/web”
ServerName www1.xx.com
ServerAlias www1.xx.com
ErrorLog “/var/log/apache/xx/xx_error_log”
CustomLog “/var/log/apache/xx/xx_access_log” common
<Directory “/infoware/xx/web”>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Location “/”>
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonPath “['/infoware/xx/web']+['/infoware/_conf/xx] + sys.path”
SetEnv DJANGO_SETTINGS_MODULE settings
SetEnv PYTHON_EGG_CACHE /tmp/cucrm//这儿是加个变量,会在下面说明
PythonDebug On
</Location>
</VirtualHost>
——————————————————————
以上配置一定要注意环境变量的配置,否则会出错!
我在配置前出现了以下错误,##################################################################
Can’t extract file(s) to egg cache The following error occurred while trying to extract file(s) to the Python egg cache: [Errno 13] Permission denied: ‘/root/.python-eggs’ The Python egg cache directory is currently set to: /root/.python-eggs Perhaps your account does not have write access to this directory? You can change the cache directory by setting the PYTHON_EGG_CACHE environment variable to point to an accessible directory.
#################################################################
解决方法就是加环境变量
SetEnv PYTHON_EGG_CACHE /tmp/cucrm//这个目录的权限属主一定要设为APACHE指定的用户,要不就777
还有另外一种解决方法,这个我没有测试,有兴趣可以去测试.网址是:
http://www.mangbar.com/document/5d023b211579e01001157eac96e30753
大概就这样,仅供参考,如果觉得麻烦的话建议FASTCGI,这个简单点.