Progmar Marcin Załęczny


Apache VirtualHost configuration for running Python scripts in Kali Linux

Install mod-wsgi Apache module for serving Python's scripts: apt install libapache2-mod-wsgi

Make following Apache modules enabled (mpm_prefork and cgi): a2enmod mpm_prefork cgi

Make sure that wsgi_module is loaded: apache2ctl -t -D DUMP_MODULES

Create in /var/www/ directory our application's entry-point file, ex. tripapp.wsgi. Create also an optional Python file, that we include in above entry point:


import sys
sys.path.insert(0, '/var/www/')

import index

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World from Application Entry Point<br/>' + index.say_hello()

    response_headers = [('Content-type', 'text/html'),
                        ('Content-Length', str(len(output)))]

    start_response(status, response_headers)

    return [output]

def say_hello():
    return "Hello world from"

Now configure Apache's VirtualHost. In order to do this, create file in /etc/apache2/sites-available directory. The content of the file is presented below:

<VirtualHost *:80>
    DocumentRoot /var/www/

    ErrorLog ${APACHE_LOG_DIR}/
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/ combined

    WSGIScriptAlias / /var/www/

    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted


Activate the created virtual host by running following command in system shell: a2ensite

Add following line to the /etc/hosts file:

Reload Apache service: systemctl reload apache2

Run your favourite viewer and go to the following address:

You should see following content generated by Python's scripts: Hello World from Application Entry Point
Hello world from