Atlantic.Net Blog

How to Install Apache with Python Mod_wsgi on Debian 10

Hitesh Jethva
by Atlantic.Net (76posts) under VPS Hosting
0 Comments

WSGI stands for “Web Server Gateway Interface,” which provides a standard and efficient method for dynamic web applications to communicate with web servers.  It is used for deploying applications written in Django, Web.py, Werkzug, and Flask. Mod_wsgi simplifies the WSGI application deployment on an Apache webserver. Mod_wsgi is an Apache webserver module that can be used to serve Python applications using the HTTP protocol.

In this tutorial, we will show you how to install Apache with Python Mod_wsgi on Debian 10.

Prerequisites

  • A fresh Debian 10 VPS on the Atlantic.net Cloud Platform
  • A root password configured on your server

Step 1 – Create an Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server.  Create a new server, choosing Debian 10 as the operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your Debian 10 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Install Python

First, you will need to install Python in your system. You can install it by just running the following command:

apt-get install python3 libexpat1  -y

Once Python is installed, you can proceed to the next step.

Step 3 – Install Apache with mod_wsgi Module

Next, you will need to install the Apache webserver package and mod_wsgi Python module in your system. Run the following command to install them:

apt-get install apache2 apache2-utils ssl-cert libapache2-mod-wsgi -y

Once all the packages are installed, restart the Apache service to apply the changes.

systemctl restart apache2

Step 4 – Configure Apache with mod_wsgi Module

First, you will need to create a Python script in your Apache web root directory. You can create it with the following command:

nano /var/www/html/wsgi.py

Add the following lines:

def application(environ,start_response):
    status = '200 OK'
    html = '<html>\n' \
           '<body>\n' \
           '<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">\n' \
           'Welcome to Apache with mod_wsgi \n' \
           '</div>\n' \
           '</body>\n' \
           '</html>\n'
    response_header = [('Content-type','text/html')]
    start_response(status,response_header)
    return [html]

Save and close the file when you are finished.

Next, you will need to create an Apache virtual host configuration file to serve the Python script with HTTP protocol.

You can create it with the following command:

nano /etc/apache2/conf-available/mod-wsgi.conf

Add the following line:

WSGIScriptAlias /wsgi /var/www/html/wsgi.py

Save and close the file. Then, activate the virtual host configuration with the following command:

a2enconf mod-wsgi

Next, restart the Apache service to apply the changes.

systemctl restart apache2

Step 5 – Verify mod_wsgi Application

Now, open your web server and visit the URL http://your-server-ip/wsgi. You will be redirected to the following screen:

Conclusion

Congratulations! You have successfully deployed Python application with mod_wsgi and Apache on Debian 10. Easily deploy a Python application in the production environment on your VPS hosting account from Atlantic.Net.

Get A Free To Use Cloud VPS

Free Tier Includes:
G2.1GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G2.1GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources