win8系统下 配置apache2.4+mod_wsgi4.4+django1.8.6+python3.4

能够整理出这一份文档,十分感谢那些热爱分享超牛博主。如果在这里您看到了似曾相识的内容,请相信自己没错,我就是学习您的分享。大笑

由于查了很多资料,具体都参考了哪些牛人的资料也记不清了,请不要责怪。至少我在传播您的知识。偷笑


安装步骤:

一、安装python3.4
       下载 python-3.4.3.amd64.msi 直接安装
        地址: https://www.python.org/downloads/
       配置环境变量:
            将python安装目录( D:\Python34; D:\Python34\Scripts; ) 加入到path中
    配置成功
二、安装django1.8.6 
       pip install Django==1.8.6
       
       下载  Django-1.8.6.tar.gz  地址: https://www.djangoproject.com/download/
        解压到python3.4安装目录  ,cmd 进入django安装目录执行语句安装: python setup.py install
        版本查看:
            创建文件:djangofirst.py 
                              import django 
                               print(django.get_version())
 
             cmd执行文件: > python djangofirst.py  
         
三、安装pip7.1.2 
       python3.4自带 pip  6.0.8,可以使用pip install --upgrade pip 升级pip至最新版本
    pip7.1.2 安装:python -m pip install -U pip  (先卸载旧版pip 重新安装新版本pip)
    pip -V :查看pip版本
四、创建Django工程、App
    创建工程:
cmd>python D:\Python34\plugins\Django-1.8.6\django\bin\django-admin.py sta
rtproject djtest

        创建app:
         cmd  >python manage.py startapp blog

六、安装Apache2.4
       下载:vc_redist.x64.exe 直接安装   vc_redist_x64/86.exe .
       下载:httpd-2.4.17-win64-VC14.zip  
       配置环境变量:path增加 D:\Apache24\bin;
        
       解压到指定目录 修改配置文件: http.conf
    ServerRoot "D:/pydj/Apache24"
    ……
    Listen 127.0.0.1:8081    #修改端口号
    ……
    ServerName www.example.com:8081    
    ……
    DocumentRoot "D:/pydj/Apache24/htdocs"
    <Directory "D:/pydj/Apache24/htdocs">
    ……
    ScriptAlias /cgi-bin/ "D:/pydj/Apache24/cgi-bin/"
    ……
    <Directory "D:/pydj/Apache24/cgi-bin">
        AllowOverride None
        Options None
        Require all granted
    </Directory>
    启动apache服务:
    cmd>httpd 
http://127.0.0.1:8081/index.html

It works!

apache配置成功
四、安装mod_wsgi
       先安装:pip install wheel
       安装 mod_wsgi-4.4.21+ap24vc10-cp34-none-win_amd64.whl
       下载:mod_wsgi-4.4.21+ap24vc10-cp34-none-win_amd64.whl
        地址: http://www.lfd.uci.edu/ ~gohlke/pythonlibs/#mod_wsgi

        pip 安装:pip install mod_wsgi-4.4.21+ap24vc10-cp34-none-win_amd64.whl

八、配置Apache2.4、mod_wsgi、django项目工程

       1. 将 D:\Python34\ mod_wsgi.so 拷贝至  D:\Java\server\Apache24\modules下
       (mod_wsgi.so 只有mod_wsgi-4.4.21+ap24vc10-cp34-none-win_amd64.whl安装成功后才能找到)

       2.修改apache2.4的http.conf文件:
            # 添加mod_wsgi.so 模块
       LoadModule wsgi_module modules/mod_wsgi.so
    3.配置django项目 修改http.conf
    #指定静态文件路径
    
    
Alias /static/ "E:/kgdjango/static/"
<Directory "E:/kgdjango/static">
     Allow from all
</Directory>
     #指定myweb项目的wsgi.py配置文件路径
    WSGIScriptAlias / D:/pydj/myweb/myweb/wsgi.py
        wsgi.py内容:
        import os
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myweb.settings")

        from django.core.wsgi import get_wsgi_application
        application = get_wsgi_application()
     #指定项目路径
    WSGIPythonPath D:/pydj/myweb
    <Directory D:/pydj/myweb/myweb>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
    推荐方式
     定义文件:d:/conf/apache_django_wsgi.conf
     内容如下:
WSGIPythonPath "E:/python/djtest"
<VirtualHost *:8081> 
    ServerName 127.0.0.1:8081
    ServerAlias localhost
    DocumentRoot E:/python/djtest
    Alias /static/ "E:/python/djtest/static"
    <Location "/static"> 
        SetHandler None 
    </Location> 
    <Directory "E:/python/djtest/static">
        Require all denied
        Require all granted
    </Directory>
    WSGIScriptAlias / "E:/python/djtest/djtest/wsgi.py"    
    <Directory "E:/python/djtest/djtest">
        <Files wsgi.py>
            Require all denied
            Require all granted
        </Files>
    </Directory>
    
    
</VirtualHost>

修改:apache的http.conf
增加:
Include "D:\Python34\plugins\wsgiconf\apache_django_wsgi.conf"
4.配置django工程setting.py
    ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值