Draw hello world with mod_wsgi

Introduction

The goal is to "draw" Hello World "using mod-wsgi". What is mod-wsgi? It is also used to use the Python Web Framework Django.

As a premise, it is assumed that the following is done. --Install pyenv and pyenv-virtualenv

environment OS: Debian 9.0 stretch Python: 3.6.3

apache2 install

install apache2

sudo apt install -y apache2 apache2-dev

mod-wsgi install

You need to be a little careful. This is because there are two ways to install it: apt-get and pip. In the case of apt-get, it is apache2's libapache2-mod-wsgi that is installed, but it will spit out warnings due to the difference between later compiled Python and running Python. Therefore, we recommend using pip to install it.

First, make sure you have selected the version of python you want to use

pyenv versions

If you can confirm, install mod-wsgi

pip install mod-wsgi

Check just in case

pip freeze | grep wsgi

mod-wsgi==4.6.5

It's OK.

apache2 settings

Unlike the case where libapache2-mod-wsgi is installed, a little setting is required. The following files are created when mod-wsgi is installed with pip.

/home/USERNAME/.pyenv/versions/3.6.3/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so

Let apache2 recognize this file.

sudo vim /etc/apache2/mods-available/wsgi.load

Write the following line. Don't forget to replace USERNAME.

LoadModule wsgi_module /home/USERNAME/.pyenv/versions/3.6.3/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so

Then enable wsgi.

sudo a2enmod wsgi

It is OK if the following comments appear.

Enabling module wsgi.
To activate the new configuration, you need to run:
  systemctl restart apache2

Please restart apache2.

sudo service apache2 restart

Apache2 settings

I will play with the Apache2 configuration files (/ etc / apache2 /), but make a backup just in case.

cd /etc/apache2/sites-available
sudo cp 000-default.conf 000-default.conf.bk
sudo vim 000-default.conf

Add the following to the last line: By the way, in vim, G (shift + g) moves to the last line.

WSGIScriptAlias /test_wsgi /var/www/html/test_wsgi.py

Create test_wsgi.py

Create the test_wsgi.py file specified in WSGIScriptAlias above.

sudo vim /var/www/html/test_wsgi.py

The contents of the file should be as follows.

def application(environ, start_response):
    status = '200 OK'
    output = b'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]

apache2 restart

Restart apache2 when the above is complete.

sudo service apache2 restart

After this, access the domain name (or IP) / test_wsgi (Http ← be careful) and you should see Hello World.

Recommended Posts

Draw hello world with mod_wsgi
hello world with ctypes
Hello, World with Docker
Hello world with flask
Hello World with Flask + Hamlish
Until hello world with zappa
Python starting with Hello world!
Hello world
Hello, world! With virtual CAN communication
[Note] Hello world output with python
Hello World! By QPython with Braincrash
Hello World with Raspberry Pi + Minecraft Pi Edition
Pymacs hello world
cython hello world
Hello World! By QPython with Brainfu * k
Hello World and face detection with OpenCV 4.3 + Python
Hello World with gRPC / go in Docker environment
Hello world with full features of Go language
Say hello to the world with Python with IntelliJ
Hello World with nginx + uwsgi + python on EC2
Create a one-file hello world application with django
First python ① Environment construction with pythonbrew & Hello World !!
Create a "Hello World" (HTTP) server with Tornado
web2py memo: Hello World
RabbitMQ Tutorial 1 ("Hello World!")
Hello World on Django
Django's first Hello World
Predicting Kaggle's Hello World, Titanic Survivors with Logistic Regression-Modeling-
Hello World with Google App Engine (Java 8) + Spring Boot + Gradle
Draw Bezier curves with Go
Hello World with Google App Engine (Java 8) + Servlet API 3.1 + Gradle
Draw a graph with NetworkX
Draw netCDF file with python
Programming language in "Hello World"
Hello World in GO language
Predicting Kaggle's Hello World, Titanic Survivors with Logistic Regression-Prediction / Evaluation-
Hello World (beginners) on Django
Draw a graph with networkx
Hello World with Google App Engine (Java 11) + Spring Boot + Gradle
Until Hello World with Flask + uWSGI + Nginx @ Sakura's VPS (CentOS 6.6)
Getting Started with Heroku-Viewing Hello World in Python Django with Raspberry PI 3
Start with Windows, not so scary Nim ① It's like hello world.
Draw unblurred sprites with cocos2d / pyglet
Draw a graph with Julia + PyQtGraph (2)
Introduction to TensorFlow --Hello World Edition
Hello world! (Minimum Viable Block Chain)
Draw Japanese with matplotlib on Ubuntu
Draw a loose graph with matplotlib
Draw a beautiful circle with numpy
Draw a graph with Julia + PyQtGraph (1)
Set multiple WSGIPythonPath with Apache + mod_wsgi
Draw a graph with Julia + PyQtGraph (3)
Run python3 Django1.9 with mod_wsgi (deploy)
Draw Koch curve with Python Turtle
cout << "Hello, World! \ N" in python
Hello World in Flask [Appropriate memo]
Code: 2 "Hello World" in "Choregraphe-Python script"
Draw a graph with pandas + XlsxWriter
Create API using hug with mod_wsgi
Draw an illustration with Python + OpenCV
Easy to draw graphs with matplotlib