Hosting a flask app

From Earlham CS Department
Revision as of 14:48, 13 September 2017 by Khojanator (talk | contribs) (Setup for Mac (Icebook, or otherwise))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Given that you have a working flask app, this is how you can host it on the server. This setup assumes that you have sudo access to the machines. In case you don't, please get in touch with Admins.

1. Decide a name for your app, and ask the admins to create a CName entry for it. Doing this at first will make sure that by the time you are done with this setup, your app will be visible to the outside world through a web address. For this setup, we will use the name of the application as $flaskApp

Setup for Mac (Icebook, or otherwise)

2. cd to /var/www/ and get the $flaskApp.

 >> cd /var/www/
 >> cp /path/to/$flaskAppDirectory .

3. Copy the flaskApp.wsgi.mock (the mock wsgi file) to $flaskAppDirectory with the name of the app ($flaskApp in this case), and cd into the directory

 >> cp flaskApp.wsgi.mock $flaskAppDirectory/$flaskApp.wsgi
 >> cd $flaskAppDirectory

4. Edit the wsgi file you just copied,

 >> vi $flaskApp.wsgi

and change the following two lines to match your configuration.

 sys.path.insert(0,"/var/www/flaskAppDirectory/") ## should be edited to have the path of your $flaskAppDirectory
 from flaskApp import app as application ## Should be edited to have the name of the python file that initiates the application in place of flaskApp

5. Edit the main python file which was runs the application ($main.py for this example)

 >> vi $main.py 

and change the following line

 app.run(debug=True, host='0.0.0.0', port=bind_port)

to

 app.run(debug=True)   # if you know the ip address of the host, you can also have host= in the arguments to the method run

6. cd to /etc/apache2/other/ and copy the flaskApp.conf.mock (the mock conf file) with the name of the app

 >> cd /etc/apache2/other/
 >> cp flaskApp.conf.mock $flaskApp.conf

7. Edit the conf file and replace the words "flaskAppDirectory" with the name of the directory you've used, and "flaskApp" with the name of your app. As a check, the word flaskAppDirectory appears 6 times, and the word flaskApp appears 4 times. So, if you replaced 10 words, you should be fine.