Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Daniel Markham10,976 Points
Python 3.5, Flask, VirtualEnv, and Apache2
I have been trying, not succeeding, in setting up a website via Digital Ocean using Python 3.5, Flask, a virtual environment, and Apache2. I have scoured the web and cannot find a decent beginner tutorial to get the website up and running, i.e. "hello world" would suffice at this point.
Does anyone have an example apache config file, wsgi file, and a low-level explanation that covers how to point Apache2 at a virtual environment? I think I am mostly struggling with getting the config file as I have found several examples of wsgi files. Just struggling putting it all together.
Thanks in advance for any help.
This is a really straight forward document, its also assuming that you are familiar with how wsgi responds to server requests, if you aren't familiar with it download:
(Foundations of Python Network Programming)
I suggest reading this book irregardless but for this particular issue focus on chapters 9,10 and 11.
Mayur PandeCourses Plus Student 11,711 Points
Daniel Markham did you manage to resolve this? I have configured my
mod_wsgi but I am still getting errors. Everything I have tried doesn't work. I have
ssh Fonzi@220.127.116.11 and my password, but each time I try to configure my apache file and wsgi file and reload apache2 nothing happens when I enter the ip address into the browser.
Daniel Markham10,976 Points
Hi Mayur Pande ,
Yes, I did get it working after a LONG time. Here is my folder structure as it stands:
/var/www/ --FlaskApp --FlaskApp --static --img -->for images --templates --venv -->virtual environment for python --__init__.py --flaskapp.wsgi
I believe you are referring to the ".wsgi" file, and here is what I have to use the virtual env:
#!/usr/bin/python activate_this = '/var/www/FlaskApp/FlaskApp/venv/bin/activate_this.py' with open(activate_this) as file_: exec(file_.read(), dict(__file__=activate_this)) import sys import logging logging.basicConfig(stream=sys.stderr) sys.path.insert(0,"/var/www/FlaskApp/") from FlaskApp import app as application application.secret_key = 'your secret key. If you share your website, do NOT share it with this key.'
I hope this helps. I had to piece together quite a few resources from the Interwebs and Gerald's resources were extremely useful as well. The flask site (bottom) and a couple of others were helpful:
Hope this helps and let me know how it goes.