Skip to content Skip to sidebar Skip to footer

My Apache Wsgi Flask Web-app Cannot Import Its Internal Python Module

I have developed Flask-Web-App which runs fine if I use python command-line directly. However, when I deployed to Apache2 with mod-wsgi it can't import its internal modules. I have

Solution 1:

Instead of:

WSGIPythonPath /var/www/FlaskApp/FlaskApp/Base/:/var/www/FlaskApp/FlaskApp/Base/Form/:/var/www/FlaskApp/FlaskApp/Base/Model/

<VirtualHost *:80>
    ServerName localhost
    ServerAdmin admin@eynaksara.com
    WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
    <Directory /var/www/FlaskApp/FlaskApp/>
        Order allow,deny
        Allow from all
    </Directory>
    Alias /static /var/www/FlaskApp/FlaskApp/static
    <Directory /var/www/FlaskApp/FlaskApp/static/>
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

try using:

<VirtualHost *:80>
    ServerName localhost
    ServerAdmin admin@eynaksara.com
    WSGIDaemonProcess myapp python-path=/var/www/FlaskApp/FlaskApp
    WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi process-group=myapp application-group=%{GLOBAL} 
    <Directory /var/www/FlaskApp>
    <Files flaskapp.wsgi>
        Order allow,deny
        Allow from all
    </Files>
    </Directory>
    Alias /static /var/www/FlaskApp/FlaskApp/static
    <Directory /var/www/FlaskApp/FlaskApp/static/>
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Changes made are:

  1. Use mod_wsgi daemon mode not embedded mode. See http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html
  2. Correct Apache directory access authorisation. That it worked as you had it suggests you have lax security settings elsewhere in Apache configuration as what you had shouldn't have worked. Have changed it to preferred mechanism, but you should work out why your Apache configuration has it allowing Apache to serve up any file in the file system.
  3. Set the correct Python module search path. Done on the daemon process group since switched to that.
  4. For use of Python main (application) interpreter context in daemon process group to avoid issues with third party extension modules for Python that will not work in sub interpreters.

Post a Comment for "My Apache Wsgi Flask Web-app Cannot Import Its Internal Python Module"