Setup for Apache2 + mod_wsgi for venv

Viewed 592

I am looking for help with putting my Apache/wsgi setup straight.

I am running:

  • Ubuntu 18.04
  • Apache 2.4 (with -dev)
  • Python 3.8 (updated from system's 3.6.9, with -dev)
  • mod_wsgi created inside venv through pip install

What I did so far

  1. Earlier, I ran dokuwiki on <foo.bar.baz/>dokuwiki/ from /var/www/html/dokuwiki/ on port :443
  2. Updated Ubuntus 18.04 python from 3.6.9 to 3.8
  3. created venv, activated and pip-installed mod_wsgi (which seems to be finally running)
  4. I tried to deploy a flask app to /var/www/html/FlaskApp
  5. Due to problems with mod_wsgi setup, I messed around with the configs, but things should (!) have been reset to standard

Where is my problem? I read the mod_wsgi documentation, but I am not able to comprehend correctly.

Below please find the different files as they are:

flaskapp.wsgi: /var/www/html/FlaskApp/flaskapp.wsgi (also in /usr/local/www/wsgi_scripts/flaskapp.wsgi which would be preferred, but has not been set up yet)

#!/usr/bin/python

import sys
import logging
#logging.basicConfig(Stream=sys.stderr)
sys.path.insert(0,"/var/www/html/FlaskApp/")
sys.path.append("/usr/local/www/")
from FlaskApp import app as application
application.secret_key = 'FOOBARBAZ'

apache_wsgi.conf: /var/www/html/FlaskApp/apache_wsgi.conf.wsgi (this has not been enabled)

<VirtualHost *>

        ServerName foo.bar.baz
        ServerAdmin flaskappconf@errormessage.com

        DocumentRoot /var/www/html/FlaskApp

        WSGIDaemonProcess flaskapp user=www-data group=www-data python-home=/usr/local/www/venv

        WSGIScriptAlias /flaskapp /usr/local/www/wsgi_scripts/flaskapp.wsgi

        <Directory /usr/local/www/wsgi_scripts/>
                Require all granted
        </Directory>

        <Directory /var/www/html/FlaskApp>
                WSGIProcessGroup flaskapp
                Require all granted
        </Directory>
</VirtualHost>

FlaskApp init: /var/www/html/FlaskApp/FlaskApp/init.py (dunder)

from flask import Flask
app = Flask(__name__)

@app.route('/flaskapp')
def hello():
    return 'Hello world!' # prev. had a print here (but used a return in my code)


if __name__ == '__main__':
    app.run()

apache2.conf: /etc/apache2/apache2.conf (pasted a clean conf, just added following)

...
ServerName foo.bar.baz
...
LoadModule wsgi_module /etc/httpd/mod_wsgi/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
...
# enable execution of php files
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
IncludeOptional /etc/phpmyadmin/apache.conf
...

000-default.conf: /etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>
        
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
    
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
    
</VirtualHost>

newtry.conf: /etc/apache2/sites-enabled/newtry.conf

LoadModule wsgi_module "/usr/local/www/venv/lib/python3.8/site-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so"
WSGIPythonHome "/usr/local/www/venv"

<VirtualHost *:80>
     ServerAdmin admin@flaskappflaskapp.com
     DocumentRoot /var/www/html/FlaskApp
     ServerName foo.bar.baz


Alias /templates/ /var/www/html/FlaskApp/FlaskApp/templates/
Alias /static/ /var/www/html/FlaskApp/FlaskApp/static/

<Directory /var/www/html/FlaskApp/FlaskApp/templates>
Require all granted
</Directory>

<Directory /var/www/html/FlaskApp/FlaskApp/static>
Require all granted
</Directory>

#<Directory /var/www/html/FlaskApp/FlaskApp>

#Require all granted
#</Directory>

WSGIDaemonProcess flaskapp
WSGIScriptAlias /test /var/www/html/FlaskApp/flaskapp.wsgi
     <Directory /var/www/html/FlaskApp>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/doku_error.log
     CustomLog ${APACHE_LOG_DIR}/doku_access.log combined


</VirtualHost>

Current apache2/error.log

[Tue Mar 16 13:58:49.837984 2021] [autoindex:error] [pid 30377] [client 192.168.3.81:53415] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,in$
[Tue Mar 16 13:58:49.949199 2021] [core:info] [pid 30377] [client 192.168.3.81:53415] AH00128: File does not exist: /var/www/html/favicon.ico, referer: http://foo.bar.baz/
[Tue Mar 16 13:58:55.001373 2021] [core:info] [pid 30375] [client 192.168.3.81:53421] AH00128: File does not exist: /var/www/html/test
[Tue Mar 16 13:58:55.471762 2021] [wsgi:info] [pid 30450] mod_wsgi (pid=30450): Python home /usr/local/www/venv.
[Tue Mar 16 13:58:55.471843 2021] [wsgi:info] [pid 30450] mod_wsgi (pid=30450): Initializing Python.
[Tue Mar 16 13:58:55.482056 2021] [wsgi:info] [pid 30450] mod_wsgi (pid=30450): Attach interpreter ''.
[Tue Mar 16 13:58:55.490749 2021] [wsgi:info] [pid 30450] mod_wsgi (pid=30450): Imported 'mod_wsgi'.
[Tue Mar 16 13:58:59.011251 2021] [core:info] [pid 30375] [client 192.168.3.81:53421] AH00128: File does not exist: /var/www/html/flaskapp

What I would like to achieve:

  • Preferably run multiple apps (dokuwiki + FlaskApp1 + ...) on port :80 (FlaskApps only would be acceptable for now) - having trouble to set up daemon.
  • Future wsgi_scripts should reside in /usr/local/www/wsgi_scripts/ (rights to www-data:www-data)

What can I try next?

0 Answers
Related