Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Distributions»Ubuntu»How to Install Apache mod_wsgi Module on Ubuntu 16.04 (Xenial)

    How to Install Apache mod_wsgi Module on Ubuntu 16.04 (Xenial)

    RahulBy RahulAugust 8, 20182 Mins ReadUpdated:September 13, 2018

    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 16.04 (Xenial Xerus).

    Step 1 – Prerequisites

    Login to Ubuntu 16.04 server console via SSH and install some prerequisites packages on the system.

    sudo apt-get update
    sudo apt-get install python libexpat1 
    

    Step 2 – Installing mod_wsgi Module with Apache

    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
    

    Step 3 – Configure Apache for WSGI Module

    Now you need to configure your Apache server to work with the mod_wsgi module. Let’s, create a python script to serve via mod_wsgi Apache module.

    sudo vi /var/www/html/wsgi_test_script.py
    

    Add the following content:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    def application(environ,start_response):
        status = '200 OK'
        html = '<html>\n' \
               '<body>\n' \
               ' Hooray, mod_wsgi is working\n' \
               '</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
    

    Step 4 – Testing

    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:

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow To Install Wine 3 on Debian 8 (Jessie)
    Next Article How to Get Current Date and Time in Golang

    Related Posts

    How to Install Composer on Ubuntu 22.04

    Updated:June 24, 20223 Mins Read

    How to Install Apache Kafka on Ubuntu 22.04

    Updated:June 5, 20225 Mins Read

    Setting Up Environment Variables on Ubuntu

    Updated:May 28, 20222 Mins Read

    How to Install Apache Solr 9.0 on Ubuntu 22.04

    Updated:May 26, 20223 Mins Read

    How to Install .NET Core (dotnet) on Ubuntu 22.04

    Updated:May 25, 20224 Mins Read

    Changing the Login Screen Background in Ubuntu 22.04 & 20.04

    Updated:May 9, 20222 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install Ionic Framework on Ubuntu 22.04
    • What is the /etc/hosts file in Linux
    • How to Install Angular CLI on Ubuntu 22.04
    • How to Install Composer on Ubuntu 22.04
    • How to Create DMARC Record For Your Domain
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.