【注】以下内容皆为转载
CentOS6.5 自带的Python版本是2.6的,已升级为2.7.6.
假设Django网站mysite的目录在/usr/local/上 (我之前放在用户文件夹中,结果一直出错)
1、安装Apache
先卸载自带的httpd
rpm -e httpd --nodeps
在网上下载四个文件
1、apr-1.4.6.tar.gz
2、apr-util-1.5.1.tar.gz
3、pcre-8.32.tar.gz
4、httpd-2.4.3.tar.gz
下载地址:
http://pan.baidu.com/share/link?shareid=169366&uk=1829018343
分别安装这四个包
apr-1.4.6.tar.gz
tar xzf apr-1.4.6.tar.gz---------------------------------解压
./configure –prefix=/usr/local/apr--------------------安装路径
make && make install----------------------------------编译&安装
apr-util-1.5.1.tar.gz
tar xzf apr-util-1.5.1.tar.gz
.configure –with-apr=/usr/local/apr
make && make install
prce
tar xzf pcre-8.32.tar.gz
./configure –prefix=/usr/local/prce
make && make install
apache
tar xzf httpd-2.4.3.tar.gz
./configure -prefix=/usr/local/apache --with-apr=/usr/local/apr/ --with-pcre=/usr/local/pcre/
make && make install
检查一下apache是否正确安装
/usr/local/apache/bin/apachectl start
然后登录127.0.0.1
2 安装mod_wsgi
下载地址:http://pan.baidu.com/s/1sjM3uY5
解压
tar zxvf mod_wsgi-4.2.5.tar.gz -C /usr/local/src/ (最好一个选项都不要改,我改过,结果解压失败了)
cd /usr/local/src/mod_wsgi-4.2.5
./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr//bin/python (指定Python的路径,因为我没有重装Python,所以用的是默认Python路径)
make && make install
3 配置apache
(假设Django网站myweb2的目录在/usr/local/上)
在/usr/local/apache/conf/httpd.conf文件中找到Directory段落,添加:
<Directory "/usr/local/mysite/">
Order deny,allow
Allow from all
Require all granted
</Directory>
WSGIScriptAlias / "/usr/local/myweb2/myweb2/wsgi.py"
其中wsgi.py的文件内容如下:
- import os,sys
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myweb2.settings")
- sys.path.append(r'/usr/local/myweb2/')
- from django.core.wsgi import get_wsgi_application
- application = get_wsgi_application()
注意sys.path.append(r'/usr/local/myweb2')这句,千万不要漏掉
最后再重启apache
/usr/local/apache/bin/apachectl stop
/usr/local/apache/bin/apachectl start
登录127.0.0.1,看到
附:
www.cnblogs.com/fnng/p/4119712.html,这篇文章介绍的时windows下Apache&Django的部署,但CentOS下可依此来完成,大同小异。