Contents:
The mod_wsgi Apache module is used for serving Python scripts over HTTP via Apache web server. This tutorial helps you to how to install Apache mod_wsgi module on Ubuntu 18.04 (Bionic Beaver).
Login to Ubuntu 18.04 server console via SSH and install some prerequisites packages on the system.
sudo apt-get update sudo apt-get install python libexpat1
Before starting, you will need to install some prerequisite Apache components in order to work with mod_wsgi. You can install all required components by simply running the following command:
sudo apt-get update sudo apt-get install apache2 apache2-utils ssl-cert
Now, install mod_wsgi Apache module by running the following command:
sudo apt-get install libapache2-mod-wsgi
Restart Apache service to get mod_wsgi to work.
sudo systemctl restart apache2
Next, create a python script to serve via mod_wsgi Apache module.
sudo vi /var/www/html/wsgi_test_script.py
Add the following content:
def application(environ,start_response): status = '200 OK' html = '<html>n' '<body>n' ' Hooray, mod_wsgi is workingn' '</body>n' '</html>n' response_header = [('Content-type','text/html')] start_response(status,response_header) return [html]
After that, you need to configure Apache server to serve this file over HTTP protocol. Let’s create a configuration file to serve wsgi_test_script.py script over a sub URL.
sudo nano /etc/apache2/conf-available/mod-wsgi.conf
Add the following content:
WSGIScriptAlias /test_wsgi /var/www/html/wsgi_test_script.py
After completing the above steps enable mod-wsgi configuration and restart Apache service.
sudo a2enconf mod-wsgi sudo systemctl restart apache2
The setup is ready now. You can test the script by accessing http://SERVER_IP//test_wsgi URL in a web browser. See below screenshot:
An alternative for the nmcli is the nmtui, short for Network Manager Text User Interface,…
MariaDB is an enhanced, drop-in replacement for MySQL. MariaDB can be a better choice for…
MariaDB is an enhanced, drop-in replacement for MySQL. MariaDB can be a better choice for…
Rclone is a command line program written in Go language, used to sync files and…
By default, authentication is disabled in MongoDB, but this is not so critical as, out…
What is Pip? pip is a tool for installing and managing Python packages. With pip…
Leave a Comment