WebFaction
Community site: login faq

Hi,

i try to setup my Flask website on WebFaction. I still created a new 'mod_wsgi 3.4/Python 2.7' application in the control panel. The new new virtualenv for the webapplication is also still created.

Can somebody help me how i have to configure Apache to run my Flask application and also to use the applications virtualenv? I couldn't find any information on how to do this.

Thanks!

asked 03 Aug '13, 03:58

Alexander's gravatar image

Alexander
112
accept rate: 0%


After a few attempts i got the site running. But i don't know if my configuration is the best - it's a really small Flask site but ps -u username -o pid,rss,cmd says its using 150 MB of memory. That seems to be a lot to me.

Anyway, got get it working i change $HOME/webapps/myapplication/htdocs/index.py:

import sys

activate_this='/home/username/virtualenvs/myvirtualenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

sys.path.append('/home/username/webapps/myapplication/htdocs')

from app import app as application

A my $HOME/webapps/myapplication/apache2/conf/httpd.conf look like this:

ServerRoot "/home/username/webapps/myapplication/apache2"

LoadModule dir_module        modules/mod_dir.so
LoadModule env_module        modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module       modules/mod_mime.so
LoadModule rewrite_module    modules/mod_rewrite.so
LoadModule setenvif_module   modules/mod_setenvif.so
LoadModule wsgi_module       modules/mod_wsgi.so

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /home/username/logs/user/access_myapplication.log combined
DirectoryIndex index.py
DocumentRoot /home/username/webapps/myapplication/htdocs
ErrorLog /home/username/logs/user/error_myapplication.log
KeepAlive Off
Listen 29991
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 1
SetEnvIf X-Forwarded-SSL on HTTPS=1
ThreadsPerChild 5
WSGIDaemonProcess myapplication processes=5 python-path=/home/username/webapps/myapplication/lib/python2.7 threads=1
WSGIProcessGroup myapplication
WSGIRestrictEmbedded On
WSGILazyInitialization On

WSGIPythonPath /home/username/webaspps/myapplication/htdocs
WSGIScriptAlias / /home/username/webapps/myapplication/htdocs/index.py

<Directory /home/username/webapps/myapplication/htdocs>
    AddHandler wsgi-script .py
    RewriteEngine on
    RewriteBase /
    WSGIScriptReloading on
</Directory>

Ok, it might work - but are there any optimizations to doo it better?

permanent link

answered 03 Aug '13, 09:27

Alexander's gravatar image

Alexander
112
accept rate: 0%

edited 03 Aug '13, 12:13

You will want to review the Mod_wsgi documentation on processes and threading and debugging to know what the various directives mean, how they apply to your code and user requirements, and how to check what is using the RAM.

permanent link

answered 03 Aug '13, 17:54

johns's gravatar image

johns ♦♦
5.0k29
accept rate: 23%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×333
×111
×52
×42

question asked: 03 Aug '13, 03:58

question was seen: 3,334 times

last updated: 03 Aug '13, 17:54

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2017 PARAGON INTERNET GROUP LIMITED
WEBFACTION IS A SERVICE OF PARAGON INTERNET GROUP LIMITED
REGISTERED IN ENGLAND AND WALES 7573953 - VAT REGISTRATION NUMBER 182147021
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM