mod_wsgi is an Apache module that provides an interface for hosting Python-based web applications under Apache. It is suitable for use in host production with high-performance production websites, as well as your average self-managed personal websites run on web hosting services. You can easily distribute applications written with frames and tools such as Django, Web.py, Werkzug, Chery.py, TurboGears and Flask with mod_wsgi.
In this tutorial we will teach you how to install and configure mod_wsgi with the Apache server on the Ubuntu 20.04 server.
- A server running Ubuntu 20.04.
- A root password is configured on the server.
Before you begin, it is a good idea to update your system with the latest version. You can update your system with the following command:
apt-get update -y
apt-get upgrade -y
After updating the system, restart it to make the changes.
By default, Python comes pre-installed on an Ubuntu 20.04 server. If it is not installed, you can install it with the following command:
apt-get install python3 libexpat1 -y
When the installation is complete, you can proceed to the next step.
Install Apache and mod_wsgi
Next, you need to install the Apache web server and mod_wsgi Python module on your system. You can install them by running the following command:
apt-get install apache2 apache2-utils ssl-cert libapache2-mod-wsgi -y
Once all the packages have been installed, you can proceed to the next step.
Configure Apache for mod_wsgi
Next, you need to create a new Python script in the default Apache root directory and serve it via mod_wsgi Apache module.
You can create it with the following command:
Add the following lines:
def application(environ,start_response): status="200 OK" html="html>n" 'n' 'n' 'Welcome to mod_wsgi Test Pagen' 'n' 'n' '