My Apache WSGI Flask web-app cannot import its internal python module
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:
- Use mod_wsgi daemon mode not embedded mode. See http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html
- 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.
- Set the correct Python module search path. Done on the daemon process group since switched to that.
- 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.