windows build django + apache environment

Introduction: Although there are many online tutorials, but between different versions of some differences, so to build their own success stories about the record

1. software versions:

① system: windows Server 2012 R2 Datacenter 64 

②python3.5.4  32 

③Django 2.0.8 

④apache 2.4.35  32 

2. environment to build:

2.1 apache download and install: Download windows apache version (according to their needs Download )

       I downloaded the httpd-2.4.35-o102p-x86-vc14.zip

2.1.1 Here I will download the installation package of the above extract to C: \ Apache24

2.1.2 modify c: \ Apache24 \ conf \ httpd.conf content

         The Define SRVROOT "/ Apache24" changed to Define SRVROOT "c: / Apache24"

         Listen 80 Listen 8000 will be changed

2.1.3 Double-click to open the c: \ Apache24 \ bin \ httpd.exe, open the program that is automatically exit failed to start.

Visual C ++ libraries to install runtime components, the following content downloaded apache above the bottom:

Download the corresponding visual C ++ libraries when transporting components:

Once downloaded, double-click the installation, the following problems occur:

The above problem: 0x80240017- unspecified error is windows server 2012 R2 system problems, the system needs to be updated KB2919355 patch: Microsoft's official patch download

Patch installation rules:

So you want to install the above patch need to download and install KB2919442 (x64): Download

2.1.4 Double-click to open the c: \ Apache24 \ bin \ httpd.exe, the program does not automatically open the exit that is success.

         在浏览器打开 http://127.0.0.1:8000

         成功出现如下内容即安装成功:

2.1.5 如果还是安装不成功,可能是端口被占用,在命令行cmd 转到httpd.exe目录下执行httpd -k install可查看失败原因。

         若是端口被占用,可用netstat -ano|findstr "被占用端口号"  被占用端口号是具体错误的端口号比如8000

         查到占用的端口的进程号,再使用 taskkill -f -pid xxx 关闭进程。

2.2 安装python (3.5.4 32)

2.2.1 下载python

2.2.2 安装

如图打钩,选择Customize installation

安装成功后显示提示。

2.3 安装Django (2.0.8 )

2.3.1下载Django

2.3.2 下载完解压后, 命令行进入解压目录:

安装成功:

安装成功使用django-admin若出现pytz错误 使用pip install -U pytz解决问题。

2.4 安装 mod_wsgi

2.4.1 下载mod_wsgi‑4.6.4+ap24vc14‑cp35‑cp35m‑win32.whl(根据实际使用版本下载,其中35表示python版本)

          备注:有些浏览器无法下载比如QQ浏览器,但Google是可以的。

2.4.2 安装

pip install mod_wsgi-4.5.24+ap24vc14-cp35-cp35m-win32.whl 

mod_wsgi-express module-config

#输出 后面部署Django+Apache需要以下的输出内容
LoadFile "c:/program files (x86)/python35-32/python35.dll"
LoadModule wsgi_module "c:/program files (x86)/python35-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp35-win32.pyd"
WSGIPythonHome "c:/program files (x86)/python35-32"

2.5 Django + Apache部署:

2.5.1 使用django-admin创建服务器项目:

#在我的C:\mycode下执行命令
c:\mycode> django-admin startproject myproject1

2.5.2 配置Apache: 修改c:\Apache24\conf\httpd.conf在其文件末尾加入如下内容

#添加mod_wsgi,这三行是安装mod_wsgi命令行中显示出来的
LoadFile "c:/program files (x86)/python35-32/python35.dll"
LoadModule wsgi_module "c:/program files (x86)/python35-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp35-win32.pyd"
WSGIPythonHome "c:/program files (x86)/python35-32"

#设置wsgi.py文件路径
WSGIScriptAlias / c:/mycode/myproject1/myproject1/wsgi.py

#指定项目目录,即你的Django项目路径
WSGIPythonPath c:/mycode/myproject1
<Directory c:/mycode/myproject1/myproject1>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

Listen 8000
ServerName 127.0.0.1:8000

2.5.3 测试:(记得把服务器的访火墙关掉,否则别的电脑无法访问)

         使用局域网的其他计算机浏览器访问

         输入:http://服务器IP:端口号/admin

         成功访问如下图:

 

Guess you like

Origin blog.csdn.net/qq_23903863/article/details/82768903