0

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
6
  • Please show the full error from the Apache log. Commented Jul 31, 2017 at 16:32
  • What are the list of files/directories in /var/www/FlaskApp and /var/www/FlaskApp/FlaskApp? What version of Python is mod_wsgi compiled for? What version of Python is your code meant to be written for? Commented Jul 31, 2017 at 20:53
  • Hey Graham, thanks for replying to my thread. I've seen that you have answered this problem for others: /var/www/FlaskApp contains [FlaskApp and flaskapp.wsgi] /var/www/FlaskApp/FlaskApp contains [myFile.py] my python code is written for python 2.7 however I'm not sure what version of python mod_wsgi is compiled for. How would I find out? Commented Jul 31, 2017 at 23:04
  • I found it Graham, mod_wsgi: Compiled for Python/2.7.8. mod_wsgi: Runtime using Python/2.7.9. Hope this helps you help me Commented Jul 31, 2017 at 23:51
  • So you do or don't have a __init__.py file in /var/www/FlaskApp/FlaskApp. You need to have it if being run with Python 2. This is why asked what Python version code was set up for. Python 3 doesn't require that file. The difference between 2.7.8 and 2.7.9 doesn't matter. Commented Aug 2, 2017 at 7:11

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.