Skip to content

Apache WSGI Install

pgalko edited this page Apr 25, 2022 · 5 revisions

Installation and setup (uses Apache/mod_wsgi):

  • Install Python 3.9 (any Python 3.x version should work)

  • Clone the repository

  • Install Python requirements

    cd to 'src' directory and run pip install -r requirements.txt

  • Install and configure PostgreSQL v13.1 (tested on 10.0 and above)
    Set path/environment variables. eg.C:\Program Files\PostgreSQL\13\lib eg.C:\Program Files\PostgreSQL\13\bin.
    Set max prepared transactions to non zero value in the 'postgresql.conf'. max_prepared_transactions = 100

  • Create download folder eg. /home/user/Data_Dump)

  • Configure and encrypt settings.ini Modify 'sample_settings.ini' to reflect your environment and use case scenario and rename to 'settings.ini' when done. Sensitive information in the .ini file will get encrypted upon the app's first execution, and the original clear text settings.ini will be deleted.

    The encryption function uses settings.ini as a base, encrypts all sensitive information in it and generates encrypted_settings.ini file which is then used by the application. The original settings.ini is automatically deleted when the application starts, or it can be deleted manually after the 'encrypt_ini_file.py' successfully executes. The 'encrypt_ini_file.py' script is executed automatically when the app ('web_app_loader_flask.py' or 'web_app_loader_apache.py') is started for the first time, or it can be executed prior, by running it manually. It will need to be executed with the same passphrase argument as will be used later for the app. If it needs to be re-run (eg passphrase change etc) and the settings.ini has been deleted, simply rename encrypted_settings.ini back to settings.ini, replace all encrypted sections with the plain text, and restart the application or run manually providing the correct passphrase.

    What gets encrypted:
    [app]: secret_key, smtp_password
    [postgresql]: password
    [dropbox]: app_secret, app_key
    [oura]: client_id, client_secret
    [strava]: client_id, client_secret
    [anticaptcha]: api_key

    At a very least you will need to provide [app]: secret_key,[postgresql]: password for the application to be able to function, the rest is optional. More info about Settings & Encryption can be found here: https://github.com/pgalko/athlete_data_warehouse/wiki/Settings-Encryption

  • Install Apache
    https://httpd.apache.org/docs/current/install.html\

    Sample Apache .conf file (Includes pg_web and superset virtual hosts):

    <VirtualHost *:80>
       ServerName www.athletedata.net
       ServerAlias athletedata.net
       Redirect / https://www.athletedata.net
    </VirtualHost>
    
    <VirtualHost *:80>
       ServerAdmin [email protected]
       ServerName pgweb-smpl.athletedata.net
      ProxyPreserveHost On
    
      <Proxy *>
           Order allow,deny
          Allow from all
      </Proxy>
       ProxyPass / http://<HOST IP>:8081/
      ProxyPassReverse / http://<HOST IP>:8081/
    </VirtualHost>
    
    <VirtualHost *:80>
       ServerAdmin [email protected]
       ServerName pgweb-usr.athletedata.net
       ProxyPreserveHost On
    
       <Proxy *>
          Order allow,deny
          Allow from all
       </Proxy>
       ProxyPass / http://<HOST IP>:8082/
       ProxyPassReverse / http://<HOST IP>:8082/
    </VirtualHost>
    
    <VirtualHost *:80>
       ServerAdmin [email protected]
       ServerName www.superset.athletedata.net
       ServerAlias superset.athletedata.net
       ErrorLog /var/www/athletedata.net/logs/error.log
       CustomLog /var/www/athletedata.net/logs/access.log combined
       WSGIDaemonProcess superset user=www-data group=www-data threads=3 home=/var/www/superset/
       WSGIScriptAlias / /var/www/superset/superset.wsgi
       <directory /var/www/superset>
            WSGIProcessGroup superset
            WSGIApplicationGroup %{GLOBAL}
            WSGIScriptReloading On
            Order deny,allow
            Allow from all
        </directory>
    </VirtualHost>
    
    <VirtualHost *:443>
       ServerAdmin [email protected]
       ServerName www.athletedata.net
       ServerAlias athletedata.net
       ErrorLog /var/www/athletedata.net/logs/error.log
       CustomLog /var/www/athletedata.net/logs/access.log combined
    
       WSGIDaemonProcess athletedataapp user=www-data group=www-data threads=3 home=/var/www/athletedataapp/
       WSGIScriptAlias / /var/www/athletedataapp/athletedataapp.wsgi
    
       SSLEngine On
       SSLCertificateFile /etc/apache2/cert/<CERT>.crt
       SSLCertificateKeyFile /etc/apache2/cert/<KEY>.key
       SSLCertificateChainFile /etc/apache2/cert/gd_bundle-g2-g1.crt
       <directory /var/www/athletedataapp>
           WSGIProcessGroup athletedataapp
           WSGIApplicationGroup %{GLOBAL}
           WSGIScriptReloading On
           Order deny,allow
           Allow from all
       </directory>
    
       Alias /static/ /var/www/athletedataapp/static/
       <Directory /var/www/athletedataapp/static>
           Order allow,deny
           Allow from all
       </Directory>
    
    </VirtualHost>
    
  • Install mod_wsgi
    https://pypi.org/project/mod-wsgi/

    pip install mod-wsgi
    

    Sample 'athletedataapp.wsgi' file:

    import sys
    sys.path.append('/var/www/athletedataapp')
    from athletedataapp import app as application
    

    Sample 'superset.wsgi' file:

    import sys
    sys.path.append('/var/www/FLASKAPPS/superset')
    from superset.app import create_app
    application = create_app()
    
  • Run sudo python web_app_loader_apache.py to start/restart Apache web server/mod_wsgi and the flask app. Once executed you will be prompted to provide an encryption password of your choice to encrypt the "settings.ini" file and all sensitive user data in the DB. It is important that you remember the password as the password is not saved and you will be asked to provide it every time you restart the app ! The autosynch loop will be also started at this time and will check for new user data automatically at the intervals specified in 'settings.ini'.

    Browse to http://domain_name_or_ip_address and you should be able to create a user login and start experimenting with different download options and settings.

    Upon first submit the user data DB and user role will be created. The DB will be accessible using the usual DB management tools like pgAdmin.
    The DB role and password for user's DB are derived from user's logon username and password. If username = [email protected] and password = pass123, the DB role will be created as johndoe with password pass123.

Clone this wiki locally