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/dev.trip.pl directory our application's entry-point file, ex.
tripapp.wsgi. Create also an optional Python file, that we include in above entry point:
tripapp.wsgi:
import sys
sys.path.insert(0, '/var/www/dev.trip.pl')
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]
index.py:
def say_hello():
return "Hello world from index.py"
Now configure Apache's VirtualHost. In order to do this, create file 001-dev.trip.pl.conf in /etc/apache2/sites-available directory. The content of the file is presented below:
<VirtualHost *:80>
DocumentRoot /var/www/dev.trip.pl
ServerName dev.trip.pl
ErrorLog ${APACHE_LOG_DIR}/dev.trip.pl.error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/dev.trip.pl.access.log combined
WSGIScriptAlias / /var/www/dev.trip.pl/tripapp.wsgi
<Directory /var/www/dev.trip.pl>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Activate the created virtual host by running following command in system shell:
a2ensite 001-dev.trip.pl
Add following line to the /etc/hosts file:
127.0.0.1 dev.trip.pl
Reload Apache service:
systemctl reload apache2
Run your favourite viewer and go to the following address:
http://dev.trip.pl
You should see following content generated by Python's scripts:
Hello World from Application Entry Point
Hello world from index.py