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»Web Servers»Apache»How to Install Apache mod_wsgi Module on CentOS 8

    How to Install Apache mod_wsgi Module on CentOS 8

    RahulBy RahulFebruary 25, 20202 Mins ReadUpdated:April 27, 2020

    The mod_wsgi Apache module is used for serving Python scripts over HTTP via the Apache web server. This tutorial helps you to how to install the Apache Python module (mod_wsgi) on CentOS 8 Linux. We will also create a sample page in Python and deploy it with the Apache web server.

    You may like:

    • How to Install Django Python Framework on CentOS 8

    Step 1 – Prerequisites

    Login to the CentOS 8 server console via SSH. Then must have python installed on our system. Use the following commands to install python as its dependencies on your system.

    sudo dnf install python3 python3-pip
    

    Step 2 – Install mod_wsgi Module

    Before starting, you will need to install some prerequisite Apache components in order to work with mod_wsgi. You can install all the required components by simply running the following command:

    sudo dnf install mod_wsgi httpd
    

    Restart Apache service to get mod_wsgi to work.

    sudo systemctl restart httpd.service
    

    Step 3 – Configure Apache for WSGI

    Next, create a python script to serve via the mod_wsgi Apache module. For testing, I have created a test_wsgi.py file under the default document root.

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

    And added the following content:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    def application(environ, start_response):
        status = '200 OK'
        output = b'Hooray, mod_wsgi is working'
     
        response_headers = [('Content-type', 'text/plain'),
                            ('Content-Length', str(len(output)))]
        start_response(status, response_headers)
     
        return [output]

    After that, configure the Apache server to serve this file over the web. Let’s create a configuration file to serve the test_wsgi.py script over a sub URL.

    sudo vi /etc/httpd/conf.d/python-wsgi.conf
    

    Add the following content:

    WSGIScriptAlias /test_wsgi /var/www/html/test_wsgi.py
    
    <Directory /var/www/html>
    Order allow,deny
    Allow from all
    </Directory>
    

    After completing the above steps enable mod-wsgi configuration and restart Apache service.

    sudo systemctl restart httpd.service
    

    Step 4 – Testing

    The setup is ready now. You can test the script by accessing the following URL in a web browser. Change your-server-ip with the actual server IP or hostname.

     http://your-server-ip/test_wsgi
    

    You will see the results as below:

    Install Apache mod_wsgi Module on CentOS 8

    Apache CentOS 8 mod_wsgi Python
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Allow HTTP and HTTPS Services in FirewallD
    Next Article How to Setup Let’s Encrypt SSL with Apache on CentOS 8

    Related Posts

    How to accept user input in Python

    2 Mins Read

    Setup Selenium with Python and Chrome on Ubuntu & Debian

    Updated:June 20, 20224 Mins Read

    Setup Selenium with Python and Chrome on Fedora

    Updated:June 18, 20223 Mins Read

    Creating Python Virtual Environment on Windows

    Updated:June 3, 20222 Mins Read

    How To Install Apache Solr 9.0 on Fedora 36/35

    Updated:May 26, 20223 Mins Read

    How to Install Apache ActiveMQ on Ubuntu 22.04

    3 Mins Read

    5 Comments

    1. Dmitry on June 29, 2021 6:20 pm

      Rahul, thanks a lot. Your post is very helpful. I am very grateful to you

      Reply
    2. Guido on April 9, 2021 7:52 pm

      Because in Centos 8 and AlmaLinux 8 the mod_wsgi is not installed as expected, you should use the next command

      dnf -y install python3-mod_wsgi

      Reply
      • Dmirty on June 29, 2021 6:17 pm

        Thank you very much, Guido. Your comment is brilliant and highly helpful

        Reply
    3. Jason Wong on July 17, 2020 1:28 pm

      I don’t think this is applicable anymore in Centos 8.0.1905 as the mod_wsgi package is no longer available

      Nearest one I can find is python*-mod_wsgi

      Reply
    4. Dan on April 27, 2020 5:50 am

      I believe ins tep 4 , the url should be http://your-server-ip/test_wsgi . since that was the alias we used. Great tutorial though!!

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    • What is difference between var, let and const in JavaScript?
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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