Apache installation and deployment instructions and common problem solving in Windows environment

1. Software preparation
1.1 Python download and installation
See blog
Link: Python download and installation
1.2 Pycharm download and installation
See blog
Link: pycharm installation
1.3 Mysql download and installation
See blog
Link: MySQL installation
1.4 Navicat download and installation
can refer to the software Install the butler.
Explanation: Pycharm is an integrated compilation environment for Python, and Navicat is used to manage Mysql. The above software is used for website development based on Mysql database and Django framework. If you want your website to run under the LAN and be accessible to other people under the LAN, first make sure to enter python manage.py runserver in the terminal and it will run under the local 127.0.0.1. Next It is to deploy the website you designed on the local area network through Apache.
2. Apache deployment
2.1 mod_wsgi download and installation
2.1.1 Download mod_wsgi
What you must remember here is to download mod_wsgi that matches your python version.
Link: Apache download address
Insert image description here
2.1.2 Note that you must copy the downloaded whl file to the virtual environment you created for your project. This may be different because everyone uses different environments. Some are python environments, and some are conda environments. No matter No matter what, put it in the script folder in the virtual environment you created for your project, so that you can install the package in the virtual environment in the next step.
2.1.3 win+R, enter cmd, open the terminal, cd into the path where whl is located, and enter the command

pip3 install "mod_wsgi-4.7.1-cp36-cp36-win_amd64.whl"

2.1.4 Successful installed mod_wsgi-4.7.1 is displayed, and then continue to enter the command. Three lines of code will appear. Be sure to record these three lines of code to facilitate subsequent changes to the files in Apache.

mod_wsgi-express module-config

Insert image description here
The three lines of code I have here are (everyone will be different depending on their own file path)

LoadFile "D:/Anaconda/envs/wangyekaifapytorch/python36.dll"
LoadModule wsgi_module "D:/Anaconda/envs/wangyekaifapytorch/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd"
WSGIPythonHome "D:/Anaconda/envs/wangyekaifapytorch"

2.1.5 mod_wsgi is installed successfully.
2.2 Apache download and installation
2.2.1 Download Apache
link: Apache download address
Select the latest version to download.
Insert image description here
2.2.2 We decompress the downloaded compressed package
Insert image description here
. After decompression, what it looks like after opening
Insert image description here
2.2.3 Win+R, enter cmd, open the terminal, cd into the path of bin in the Apache24 folder, and enter the command

httpd.exe -k install -n "apache2.4"

The successfully installed message indicates that the service was successfully created.
2.2.4 Deploy Apache.
Open the folders in order, find httpd.conf and make changes
Insert image description here
Insert image description here
. Note that there are three major categories that need to be changed.
The first category is the installation path of Apache
Insert image description here
. The second category is the IP address and port number to be deployed.
Insert image description here
Insert image description here
Two points need to be emphasized here.
The first is the way to view the IP address.
win+R, enter cmd, open the terminal, enter the following command

ipconfig

The second point is that port numbers cannot conflict
. The third category is to set the project path and the path of the virtual environment.
Insert image description here
Special attention should be paid here:
First point: If there are invalid characters such as spaces and . in the project path or virtual environment, you can add quotation marks. If you still cannot start Apache after adding quotation marks, it is recommended to change the path or file Please change the name so that it does not contain such illegal or invalid characters.
Second point: How to check whether the changes to httpd.conf are correct?
Win+R, enter cmd, open the terminal, cd into the path of bin in the Apache24 folder, enter the command httpd-t,
Insert image description here
if syntax OK is reported, then it is httpd. The changes to conf are correct. If it is incorrect, it will report which row is incorrect. Just change it according to the index.
2.2.5 Finally, let’s start Apache.
We open the exe software in order:
Insert image description hereInsert image description here
Insert image description here
click start. If there is a green sun, there is an 80% probability that the deployment is successful.
If the deployment is unsuccessful, a failed error will be reported, and we have to check httpd.conf. Another method is to open the error log and check the error. The location of the error log is
Insert image description here
Insert image description here
You can open this file to view the source of the error.
2.2.6 Other issues that need attention:
First, sometimes the static file cannot be loaded, then we need to copy a static file and enter the command in the terminal

python manage.py collectstatic

The second one has a green little sun, but it keeps spinning when using IP and port to access the website. Then we need to add this line of code to the previous httpd.conf.

WSGIApplicationGroup %{
    
    GLOBAL}

Third, if you can only access it by yourself, it may be a firewall problem. Just turn off the firewall.

Guess you like

Origin blog.csdn.net/m0_46155417/article/details/134003257