PHP前端开发

windows10下安装搭建django1.10.3和Apache2.4的详细教程

百变鹏仔 3小时前 #Python
文章标签 教程

最近发现很多教程都是在linux上搭建,windows上似乎天生不太适合,但是我还是愿意试试这个坑。下面这篇文章主要给大家介绍了在windows 10系统下安装搭建django1.10.3和apache2.4的方法,需要的朋友可以参考借鉴,下面来一起看看吧。

环境介绍

  • python3.5.2 64位

  • django 1.10.3

  • apache 2.4 64位

  • windows 10

重点在apache上。

python 和django 相信有兴趣看这篇文章的基本上也都已经了解了。

安装Apache2.4

地址:www.apachelounge.com/download/

         下载:vc_redist.x64.exe 直接安装  vc_redist_x64/86.exe.

下载:httpd-2.4.17-win64-VC14.zip  

       配置环境变量:path增加D:Apache24in;

解压到指定目录 修改配置文件: http.conf (下面内容中的ServerRoot改成你自己的实际Apche解压路径)

 ServerRoot "D:/Apache24" …… Listen 127.0.0.1:8081 #修改端口号 …… ServerName www.example.com:8081  …… DocumentRoot "D:/Apache24/htdocs" <directory> …… ScriptAlias /cgi-bin/ "D:/Apache24/cgi-bin/" …… <directory>  AllowOverride None  Options None  Require all granted </directory></directory>

启动apache服务:

    cmd&gt;httpd

    127.0.0.1:8081/index.html

   It works! apache配置成功

安装mod_wsgi

先安装:pip install wheel

安装mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.whl

下载:mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.whl

地址:www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi

pip 安装:pip install mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.whl

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

1. 将C:Python35mod_wsgi.so 拷贝至 D:Apache24modules下

       (mod_wsgi.so 只有mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.whl安装成功后才能找到)

2.修改apache2.4的http.conf文件:

 #添加mod_wsgi.so 模块 LoadModule wsgi_module modules/mod_wsgi.so

3.配置django项目 修改http.conf

#添加mod_wsgi.so 模块 LoadModule wsgi_module modules/mod_wsgi.so #指定静态资源路径Alias /statics/ F:/pydj/newsCollection/toutiao/statics/<directory> Require all granted </directory> #指定newsCollection项目的wsgi.py配置文件路径 WSGIScriptAlias / F:/pydj/newsCollection/newsCollection/wsgi.py#指定项目路径 WSGIPythonPath F:/pydj/newsCollection <directory>  <files>   Require all granted  </files></directory>


wsgi.py内容:

import osos.environ.setdefault("DJANGO_SETTINGS_MODULE", "myweb.settings")from django.core.wsgi import get_wsgi_applicationapplication = get_wsgi_application()


#注意上面的myweb,是改成自己的项目名称,比如上图中 newsCollection。参考上上图中的目录结构。

配置django工程setting.py

ALLOWED_HOSTS = ['127.0.0.1', 'localhost']

最后告诉一点 Apche 启动的时候报错会有log, httpd-2.4.23-x64-vc14-r3Apache24logs 目录下 error信息,慢慢排错

总结