Flask deployement on lighttpd and raspberry pi
I believe the problem is that in your hello.fcgi file, you are importing a module named yourapplication
, however, the flask application you created is named hello
.
Try changing this line:
from yourapplication import app
tofrom hello import app
Edit: Also - double check your url when testing - since your @app.route
is set to the root, you must include the trailing slash in your url, eg:
and not
First, like c_tothe_k said, you need to change yourapplication
to hello
in your hello.fcgi
file.
I found the instructions in the flask documentation to be lacking. It recommends reading this page, and so do I, http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI#Troubleshooting
The bottom of the page has an example lighttpd.conf
I followed a hybrid of the instructions in the Flask documentation and the above page. I renamed the .fcgi
file to .py
, as shown in the Lightty documentation.
You don't have to worry about the .sock file if you follow this approach. It's the old way that lighttpd used to communicate with a FastCGI process, using a UNIX socket. It just needs to be here so the config parser isn't broken.
I used the following in my lighttpd.conf. Your other files look fine otherwise.(Note, this will put your app under /hello
, and not /
.)
fastcgi.server = ( "/hello" => ( "python-fcgi" => ( "socket" => "/tmp/fastcgi.python.socket", "bin-path" => "/var/www/demoapp/hello.py", "check-local" => "disable", "max-procs" => 1, ) ))
What worked for me is putting config part into /etc/lighttpd/conf-enabled/10-fastcgi.conf
instead of /etc/lighttpd/lighttpd.conf
I am guessing that file appears there after you run sudo lighttpd-enable-mod fastcgi
I also ran pip3 install flup-py3
to make sure that python3 support is there.