WebFaction
Community site: login faq

I'm a brand new WebFaction user, and relatively new to Python and Flask. I've built out a couple of apps before hosted on Heroku but this will be my first time doing much of the config myself. I'd like to ask a few questions about the way others deploy their apps to the server. This is a basic website for a photographer with dynamic gallery routes which will pull JSON data from the database. If it matters, here's a static version:

http://rk.commadelimited.com/

First off, here's some details about my app:

Directory structure

-Procfile
-app.py
-static
----css
----fonts
----img
--------photos
----js
--------vendor
-requirements.txt
-templates

Procfile

web: python app.py

requirements.txt

Flask==0.9
Jinja2==2.6
Werkzeug==0.8.3
distribute==0.6.28
wsgiref==0.1.2

I'm currently running the app locally using foreman. Nice and simple, but it requires me to "start" the app each time I want to access it.

1) How do I set up the server so that it runs all the time?

2) I've heard people talk about using a web server for funneling assets (css, js, imgs) while mod_wsgi serves the Python content. Right now my assets are being referenced using /static/<asset>. Is this a problem when deploying to WebFaction?

3) How do I actually deploy? The website already has a Git repo hosted on Github. Is it possible for me to dev locally, commit to Github then pull from Github to the server?

I'm sure I'll have more questions later, but this should get me going. Thanks in advance.

asked 12 Mar '13, 00:26

commadelimited
123
accept rate: 0%

edited 12 Mar '13, 00:39


1) How do I set up the server so that it runs all the time?

The best way to do this, in my opinion, is to use cron. A full example of a script which can very reliably keep a program running is available here.

2) I've heard people talk about using a web server for funneling
   assets (css, js, imgs) while mod_wsgi serves the Python content.
   Right now my assets are being referenced using /static/<asset>.
   Is this a problem when deploying to WebFaction?

It's not a problem, and in fact mapping all of your static assets under the "/static" URL path will make it even easier to serve this media efficiently on WebFaction. We have a front-end Nginx server which is very efficient at serving static media. You can create a static media application (or alternatively a symbolic link to static-only application, which works similarly) and then mount that application at "/static" on your website record. Then, all files under this URL will be served by Nginx directly from the hard disk, which is very efficient.

3) How do I actually deploy? The website already has a Git repo
   hosted on Github. Is it possible for me to dev locally, commit
   to Github then pull from Github to the server?

Certainly. git is installed on all of our servers, so you can clone your website on the server, and then just git pull to update it. Most likely your webroot is in a subdirectory of the repository, so you would create a Symbolic Link to static/CGI/PHP that uses the extra_info field to point to the webroot in your git repository, then mount that application to a website record.

Hope that helps!

permanent link

answered 12 Mar '13, 01:55

ryans ♦♦
5.0k93360
accept rate: 43%

edited 12 Mar '13, 02:01

Hey Ryan...

I'm trying to walk through your suggestions and I'm doing okay so far....but I'm sort of stuck on the "static" website part. I've logged in to the control panel and done the following:

  1. Clicked Domains / websites
  2. Clicked websites
  3. Clicked add new website
  4. Typed "static" into the name field
  5. Attached a static app that I created.

But when I try to add richkphoto.com/static it tells me that it's not a valid domain name. I've also tried www.richkphoto.com/static with the same results. Am I doing something wrong?

Also, on a related note, what would you say is the best option for uploading content from my local machine into the static directory?

(19 Mar '13, 20:18) commadelimited

You may submit a support ticket and we can investigate further. I personally use FileZilla with SFTP to move content to the server.

(19 Mar '13, 21:43) johns

Okay. One more question and then I think I might be done. Thanks to Valentin (hi Valentin) I got my static files issue resolved.

Now I'm ready to get this website up and running and I'm at a loss on how to do it. I originally created a mod_wsgi 3.4/Python 2.7 app which was located at /home/rskalonick/webapps/<appname>. I cloned my repo there, then attached the web app to my domain name. When I visited my domain I saw the following content

Welcome to your mod_wsgi website! It uses:
Python 2.7.3 (default, May 18 2012, 14:51:16) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)]

which is the output of the index.py file located in /home/rskalonick/webapps/<appname>/htdocs. My main file is called app.py and contains the following code:

import os
from flask import Flask, render_template, flash, redirect

app = Flask(__name__)
app.debug = True

# MAIN APPLICATION
@app.route('/')
@app.route('/work/<gallery>/')
def index(gallery='home'):
    return render_template('index.html', gallery=gallery)

@app.route('/views/<view>/')
def view(view):
    return render_template(view + '.html')

if __name__ == '__main__':
    # Bind to PORT if defined, otherwise default to 5000.
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)

Because index.py was clearly being rendered I tried renaming my app.py to index.py but that didn't work. I'm sure I'm missing something but I could use some guidance please.

Thanks in advance.

(21 Mar '13, 21:03) commadelimited

Add something like this to your httpd.conf...

WSGIScriptAlias / /home/you/webapps/your_app/path/to/app.py

... then restart your Apache.

(22 Mar '13, 11:00) seanf
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:

×337
×52
×44
×32

question asked: 12 Mar '13, 00:26

question was seen: 5,587 times

last updated: 22 Mar '13, 11:01

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM