A simple Python Flask app on WebFaction

Flask is a popular Python-based micro framework. Here is how to install it on WebFaction.

This is based on the Flask instructions and the WebFaction instructions.

  1. Log into your WebFaction control panel
  2. Domains/Websites -> Applications -> Add new application
    1. Name: FlaskTest
    2. mod_wsgi
    3. mod_wsgi / Python 2.7
    4. (keep port closed)
  3. Domains/Websites -> Websites
    1. Click on website
    2. Add an application -> Reuse an existing application
    3. Select flasktest, url: http://cm-demo.com/flasktest
    4. Save the Website (important: this step is easy to miss, I’ve missed it myself a few times)
  4. ssh into host
    1. cd webapps/flasktest
    2. vi setup.sh
    3. cut and paste script from https://community.webfaction.com/questions/12718/installing-flask
    4. Change APPNAME and URLPATH (e.g. /foo)
    5. exit vi (<esc>ZZ)
    6. sh setup.sh
  5. Test it: point your browser to <domain>/foo
    1. This should show “Hello World!”
    2. Edit webapps/flasktest/flasktest/__index__.py, line:
      return “Hello World!”
      to return some different text
    3. Refresh page in browser
    4. Browser should now show the new text
  6. Set up the static files – make all files in /foo/static static:
    1. Domains/Websites -> Websites
    2. Click on website
    3. Add an application
      1. Create a new application
      2. Name: flasktest_static
      3. Symbolic link
      4. Symbolic link to static-only app
      5. Extra info: /home/<user_name>/<webapps/<app>/<app>/static
    4. Create the static folder
    5. Create a test page in the new static folder
    6. Try loading the page in your browser