Deploy Django using Apache on Windows

Software Environment:


Apache+Python3.6.3+Django

System environments where this method has been tested:

Windows7Windows10Windows Server2008

Other Windows should be similar.

1. Things that need to be downloaded and installed:

Apache2.4 :
Link: https://pan.quark.cn/s/8b251585e0f2
Extraction code: F8ki
Python3.6.3 (must be installed in the default path):
Python Release Python 3.6.3 | Python.org
Django:
python installed After that, you can install it directly with pip

pip install django

Download and install mod_wsgi ( download from the network disk above ):

pip install "mod_wsgi-4.5.17+ap24vc14-cp36-cp36m-win_amd64.whl"

Two: Modify the configuration file

Unzip the Apache2.4 downloaded above (it is recommended to place it in the root directory of the system disk)
and find the following target file.
Open it and edit it.

Apache24\conf\extra\Django.conf

Apache24\conf\httpd.conf


 

After modification, save.
 

3. Start the service

Open the directory Apache24/bin directory

After double-clicking apache.exe , open the browser and enter http://127.0.0.1:8888/

Deployment successful! ! !


 

=============================Dividing line==================== ====================

4. Using ApacheMonitor.exe to open requires installing the Apache service

Enter the Apapche/bin directory and enter the CMD command line

httpd.exe -k install -n "lookalan"   #lookalan为Apache在windows的服务中的名字


Lookalan is the name of Apache in the windows service
and can be customized, for example:

httpd.exe -k install -n "api01"

After installation, it can be found in the system's " Services " and can be set to start automatically at boot.

5. If you encounter an error during deployment, you can try the following solutions

Enter the Apapche/bin directory, enter the CMD command line and
enter directly:

httpd.exe

Check the cause of the error:

httpd.exe: Syntax error on line 185 of E:/Apache24/conf/httpd.conf: 
Cannot load c:/users/administrator/appdata/local/programs/python/python36/lib/site-packages/
mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd into server: 
\xd5\xd2\xb2\xbb\xb5\xbd\xd6\xb8\xb6\xa8\xb5\xc4\xc4\xa3\xbf\xe9\xa1\xa3


The above error is caused by not following the above steps to install:
mod_wsgi-4.5.17+ap24vc14-cp36-cp36m-win_amd64.whl


There are other errors, such as port numbers being occupied, which can be detected using this method.

You can also view Apache's error log to detect errors. Log file path:

Apache24\logs         # 日志文件夹
Apache24\logs\access.log  # 访问日志
Apache24\logs\error.log  # 错误日志


 

Guess you like

Origin blog.csdn.net/qq_33613696/article/details/82257491