Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask deployement on lighttpd and raspberry pi

I'm trying to deploy a hello flask app to a raspberry pi using lighttpd fastCGI.

I followed the instructions on the http://flask.pocoo.org/docs/0.10/deploying/fastcgi/ to the best of my ability

Here is my flask app (/var/www/demoapp/hello.py)

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World From Flask Yeh!"

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000)

And here is my .fcgi file (/var/www/demoapp/hello.fcgi)

#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from yourapplication import app

if __name__ == '__main__':
    WSGIServer(app).run()

And here is what I added to my /etc/lighttpd/lighttpd.conf

fastcgi.server = ("/hello.fcgi" =>
    ((
        "socket" => "/tmp/hello-fcgi.sock",
        "bin-path" => "/var/www/demoapp/hello.fcgi",
        "check-local" => "disable",
        "max-procs" => 1
    ))
)

alias.url = (
    "/static/" => "/var/www/demoapp/static/",
)

I get a 404 Not Found error

By the way what is the /tmp/hello-fcgi.sock where do I get this file

Please help. I'm essentially trying to find a simple way to deploy flask on my raspberry pi web server. I have tried several methods. The fastcgi seemed to be the easiest. If there is an easier way then let me know please.

Thank you

Vincent

like image 301
Vincent Roy Avatar asked May 08 '15 09:05

Vincent Roy


1 Answers

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 to from 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:

http://xxx.xxx.x.xx/hello.fcgi/

and not

http://xxx.xxx.x.xx/hello.fcgi

like image 193
c_tothe_k Avatar answered Oct 12 '22 08:10

c_tothe_k