64位win8 配置Apache2.4+mod_msgi4.4.21+django1.8.6+python3.4

学习了很多前人分享的资料,整理如下:

安装步骤:

一、安装python3.4
       下载 python-3.4.3.amd64.msi 直接安装
       配置环境变量:
            将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']
posted @ 2015-11-25 08:40  firecrow  阅读(338)  评论(0编辑  收藏  举报