本文记录在windows部署python网站的过程,其中部署的服务器软件为apache,数据库为mysql,python框架为django
1.安装python
安装python,文件名为python-2.7.msi,安装完毕后,配置环境变量,将安装路径 C:\wamp\Python2.7;添加到系统环境变量。2.安装apache
安装apache,安装文件名:httpd-2.2.25-win32-x86-openssl-0.9.8y,安装路径为C:\wamp\apache2.23.安装mod_wsgi
将mod_wsgi.so文件(解压自 mod_wsgi-3.5.ap22.win32-py2.7)复制到Apache的modules目录下。
同时打开 apache配置文件 http.conf
添加对mod_wsgi的调用:
LoadModule wsgi_module modules/mod_wsgi.so4.安装mysql
参见网上常见的安装教程即可。注意记录mysql的端口、数据库名称、密码,在配置网站配置文件时要匹配。5.安装python提供的mysql驱动
6.安装django-1.6.2
安装django-1.6.2,并讲生成的bin目录添加到系统环境变量:
C:\wamp\Python2.7\Lib\site-packages\django\bin;7.安装包 setuptools
以下8-9步根据实际项目可选
8.安装包django-rest-framework-2.3.14
9.安装包 openpyxl-2.1.2
10.复制应用程序到相应目录
将python网站目录拷贝到指定文件夹,这里是C:\wamp\Project_first11.创建一个启动应用的bat
创建一个bat,用于启动网站,内容为:
python C:/wamp/workspaces/Project_first/manage.py runserver- 12.apache配置文件httpd.conf的修改
这里我修改的内容为:以C:/wamp开头的部分:
- 12.apache配置文件httpd.conf的修改
<Directory "C:/wamp/workspaces">
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "C:/wamp/workspaces">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>