The online Django deployment to Apache's article quite a lot, but according to everyone's operation, and did not once succeeded, or encountered some problems, here are the following several situations.
1. The Mod_wsgi version problem found on the web causes the dynamic library to not load.
2. Configuration issues, because of the Apache, Python, and MOD_WSGI versions are involved, so the configuration may not be the same.
Here I write down the problems and solutions I have encountered in detail. The experience of failure can be skipped.
Failure experience
My environment is python2.7.11 64-bit version, Apache I chose 2.4.20x 64-bit version, here is one thing to ensure that the Apache and Python version must be consistent (and to use the same compiler compiled, Generally python2.x version is compiled with VC9, that is VS2008), if we choose to use the compiled Mod_wsgi, please go to the following link to download:
Http://www.lfd.uci.edu/~gohlke/pythonlibs#mod_wsgi
I did download it, but I failed.
The reason for the failure is that I think I have a python2.7 32-bit version installed on my machine, but it's actually 64-bit. So I extracted the various versions of the WHL file, the mod_wsgi.so file to be replaced, or failed. No version, I still do not want to compile the Apache version of the various downloads, found or not ah? It seems still can not be lazy ah, so I adopted their own compilation, because I did not install VS2008 on the computer, so I downloaded the VS2008, here is special to note VS2008 installed on 64-bit computer is not installed VC64 bit of the compiler, If you are using a 64-bit python, be sure to tick the VC64-bit component, otherwise you will not be able to compile it (because I installed it by default, so I found that Vcvarsall.bat AMD64 did not install the component error). So this place must be noticed. VS2010 if installed on a 64-bit computer, the 64-bit compiler will be installed by default.
Detailed operation procedure (self-compiling)
1. Introduction to the Environment:
python2.7.11 64-bit
Apache 2.4.20 64-bit VC9 compiled version
It is explained here that you may sometimes be confused about the version of the VC compiled, please run Python directly at the command line, this time will show the Python detailed version information, as well as the compiler and compiler version, for example, is my: python2.x.
MSC description is compiled by Microsoft compiler v.1500 here may be some people do not know, you can see my last article Python compiler counterpart, V1500 is representative of the compiler version of VC9, so here can be sure that my Python version is vc9 compiled. This ensures that Python and Apache are compiled with the same compiler (same version).
2. Download the MOD_WSGI source code
One hears the source code, the domestic can download the estimate is GitHub, sure enough MOD_WSGI code is hosted on GitHub, the address is as follows:
Https://github.com/GrahamDumpleton/mod_wsgi
3. Compiling
Unzip the downloaded Mod_wsgi-develop.zip file into the Mod_wsgi-develop folder, open the Win32 folder, and you can see the following directory structure:
Open the Ap24py27-win32-vc9.mk file, (Here you choose the Mk file to compile according to your environment)
[Plain]View PlainCopyprint?
- Apache_rootdir = c:\Apache24-win64-VC9
- Python_rootdir = c:\Python27-win64-VC9
- Python_version = 27
- Include Common-vc9.mk
Change Apache_rootdir and Python_rootdir to your actual location
For example, my environment is this:
[Plain]View PlainCopyprint?
- Apache_rootdir = E:\windows_softs\apache64\Apache24
- Python_rootdir = c:\Python27
- Python_version = 27
- Include Common-vc9.mk
This time, directly using the corresponding batch to compile, my environment I choose is build-win64-vc9.bat.
Alternatively, you can open VS2008 's compile command line (if 64 bit, select the command line compatible with x64)
Open the CD to your source code directory and do the following:
nmake/f ap24py27-win64-vc9.mk Clean
nmake/f ap24py27-win64-vc9.mk Install
Can. If it is not compiled, please check the compiled output, whether your Python or Apache directory is not specified correctly.
4. Configure Apache
Once compiled, the mod_wsgi.so file is automatically copied to your Apache/modules directory, which you only need to configure.
There are several important parameters that must be configured when configuring the
<1> Add Modules
[Plain]View PlainCopyprint?
- LoadModule Wsgi_module modules/mod_wsgi-py27-vc9.so
<2> Specify the location of Python (if not specified, Apache Error.log will report importerror:no module named site error)
Wsgipythonhome c:/python27
<3> Configure Django Apps
[Plain]View PlainCopy print?
- #指定myweb项目的wsgi. py configuration file path
- wsgiscriptalias/g:/localsvn/trunk/python/django/myblog/myblog/wsgi.py
- #指定项目路径
- Wsgipythonpath G:/localsvn/trunk/python/django/myblo
- <directory g:/localsvn/trunk/python/django/myblog>
- <files wsgi.py>
- Require all granted
- </Files>
- </Directory>
- #配置static的目录, you need to turn debug mode off in Django settings, and specify Static_root, same as this directory
[Plain]View PlainCopy print?
- #如果有需要可以配置上传目录MEDIA_ROOT, corresponding Media_url
- Alias/static g:/localsvn/trunk/python/django/myblog/myblog/static
- <directory g:/localsvn/trunk/python/django/myblog/myblog/static>
- AllowOverride None
- Options None
- Require all granted
- </Directory>
Once configured, launch the Apache server, if you can directly access the Django Admin URL, then congratulations, the configuration is successful. In addition, Apache's default port is 80, which can be configured according to the actual situation if necessary.
Django deployed to Apache (very important, 3 versions to be consistent, 32-bit is 32-bit)