Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of configuring python mod_wsgi in apache

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to configure python mod_wsgi in apache". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to configure python mod_wsgi with apache".

Apt-get upgrade

# update source apt-get update

Python environment installation

# install python3apt-get install python3python-Vls / usr/bin/python*cd / usr/bin/ln-s python3 pythonpython-V# basic installation apt-get install curl wget vim# time zone setting or tzselectapt-get install tzdatadate-R# install pipcd tmp/curl https://bootstrap.pypa.io/get-pip.py-o get-pip.pypython get-pip.py error Traceback (most recent call last): File "get-pip.py", line 22308 In main () File "get-pip.py", line 197, in main bootstrap (tmpdir=tmpdir) File "get-pip.py", line 82, in bootstrap import pip._internal File "/ tmp/tmpslqx710t/pip.zip/pip/_internal/__init__.py", line 40, in File "/ tmp/tmpslqx710t/pip.zip/pip/_internal/cli/autocompletion.py", line 8, in File "/ tmp/tmpslqx710t/pip.zip/pip/_internal/cli/main_parser.py" Line 7, in File "/ tmp/tmpslqx710t/pip.zip/pip/_internal/cli/cmdoptions.py", line 15, in ModuleNotFoundError: No module named 'distutils.util' need to install apt-get install python3-distutilspython get-pip.pypip list

Django installation

# django installation pip install djangopip install requestspip install openpyxlpip install six# needs to be installed before installing mysqlclient, otherwise the error listed below will be reported apt-get install libmysqlclient-dev python3-dev build-essentialpip install mysqlclient error 1.OSError: mysql_config not found2. Error: command 'x86' 64murf LinuxMui GnuMurgcc' failed with exit status 1

Apache2 environment installation

# install apachesudo apt-get install apache2# start apachesudo service apache2 start# install mod_wsgisudo apt-get install libapache2-mod-wsgi-py3# verify mod_wsgi install sudo find /-name mod_wsgi.so# principle actually install libapache2-mod-wsgi-py3 will generate a mod_wsgi.so file Located in / usr/lib/apache2/modules/mod_wsgi.so and the association between apache2 and it is located in the following root@fe71dd7317b0:/etc/apache2# cat mods-available/wsgi.loadLoadModule wsgi_module / usr/lib/apache2/modules/mod_wsgi.so, you should pay attention to the version of python3. The default source of ubuntu16.04 is python3.5, and the mod_wsgi installed with the above command is 3.5. Some need to change to install mod_wsgi through pip. If you modify the path of mod_wsgi.so in mods-available/wsgi.load, you can see the following (but this article is about Ubuntu18.04) LoadModule wsgi_module "/ usr/local/lib/python3.6/dist-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"

Verify mod_wsgi

Edit the test script vim / var/www/html/wsgi_test_script.py

Def application (environ, start_response): status = '200OK' output = b'Hello Worldwide' Response_headers = [('Content-type',' text/plain'), ('Content-Length', str (len (output))] start_response (status, response_headers) return [output]

Configure wsgi

Vim / etc/apache2/apache2.conf

# finally add WSGIScriptAlias / test_wsgi / var/www/html/wsgi_test_script.py

Restart apache2

Service apache2 restartcurl http://localhost/test_wsgiroot@5ee5ff2c92c7:/usr/bin# curl http://localhost/test_wsgiHello wordmakers # output represents success!

two. Run the django program through wsgi

Cd / var/wwwdjango-admin startproject zq# config wsgi WSGIScriptAlias / / var/www/zq/zq/wsgi.pyWSGIPythonPath / var/www/zq Require all granted# note that if WSGIPythonPath is not configured, the zq module may not be able to find # restart apache2service apache2 restart# testcurl http://localhost/. I believe you have a deeper understanding of "how to configure python mod_wsgi with apache". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report