How deploy Flask application on Webfaction?


Anybody know how to deploy a simple Flask application on Webfaction? I know Webfaction support mod_wsgi and I read the guide on the Flask site but still I can't make my app working. Anybody have a working configuration?

UPDATE to answer a comment by Graham Dumpleton.

I get a 500 Internal server error. Apache does not show any error in the logs. The WSGI script is executed and seems to create the application correctly, but I keep getting a 500 error.


7/19/2010 11:12:50 AM

Accepted Answer

I got it working with the following procedure:

  • create and app named 'myapp' of type mod_wsgi 3.3/Python 2.7. Webfaction will create the following folders:

         |- apache2
         |- htdocs
  • Webfaction will also automatically create a simple script in your htdocs directory. Check if the sample script work visiting the root of your newly created application (to do thin on Webfaction you need to "mount" the app on a website). If it's all OK modify the script deleting the content and adding:

    from myapp import app as application
  • In apache2/conf/httpd.conf add the follwing lines:

    WSGIPythonPath /home/username/webapps/myapp/htdocs/
    #If you do not specify the next directive the app *will* work but you will
    #see in the path of all subdir
    WSGIScriptAlias / /home/username/webapps/myapp/htdocs/
    <Directory /home/username/webapps/myapp/htdocs>
        AddHandler wsgi-script .py
        RewriteEngine on
        RewriteBase /
        WSGIScriptReloading On
  • Restart apache2

6/7/2011 11:36:52 AM

You need to set up a "Custom app (listening on port)" application. Make a note of the port that is assigned. Then in your Flask code, you need to put hardcode the port:

if __name__ == __main__:'' port=XXXXXXX)

Where you substitute XXXXXXX with the port that is randomly assigned to your custom app.

Hope that helps.


Please use Raben's Answer, this way should not to be used in Production.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow