Reputation: 51
I'm using a raspberry pi with debian linux mod_wsgi and flask. I used this tutorial to set everything up and the python script will run if I run the command
python myFile.py
However, when I try to run it from apache I get an HTTP 500 error.
This is my wsgi file:
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,'/var/www/FlaskApp/')
from FlaskApp import app as application
this is my .conf file:
<VirtualHost *:80>
ServerName (my-server-ip)
ServerAdmin (my-Email)
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>
these are the permissions on the wsgi file
-rw-r--r-- 1 root root 211 Jul 30 18:51 flaskapp.wsgi
I've looked at many different tutorials but have yet to find a solution...
I am sure that I am not running a virtual environment for my python file and know that that could be an issue but am unsure how to solve that. Thanks for the help in advance.
this is the error that Im getting:
[Mon Jul 31 17:09:29.367693 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373] mod_wsgi (pid=2921): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module.
[Mon Jul 31 17:09:29.367924 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373] mod_wsgi (pid=2921): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'.
[Mon Jul 31 17:09:29.368074 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373] Traceback (most recent call last):
[Mon Jul 31 17:09:29.368221 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373] File "/var/www/FlaskApp/flaskapp.wsgi", line 8, in <module>
[Mon Jul 31 17:09:29.368643 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373] from FlaskApp import app as application
[Mon Jul 31 17:09:29.368793 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373] ImportError: No module named FlaskApp
Upvotes: 0
Views: 5524
Reputation: 51
This answer came from Graham Dumpleton:
When using python 2 there must be a file named __init__.py
in the project folder! In my case the path to that folder happened to be /var/www/FlaskApp/FlaskApp
.
Upvotes: 3