Skip to content

Instantly share code, notes, and snippets.

@piroux
Created January 14, 2011 23:45
Show Gist options
  • Save piroux/780520 to your computer and use it in GitHub Desktop.
Save piroux/780520 to your computer and use it in GitHub Desktop.

The purpose of this document is to help you finding the right way to congigure mod_wsgi with Apache on the servers of [alwaysdata](http://alwaysdata.com). So, without further ado, let's get the basic "Hello World" app going.

On jan.11, we will use :

Let's go.

So we assumin you have mod_wsgi installed, and a apache.conf that looks like this :

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so-2.6 WSGISocketPrefix run/wsgi

<VirtualHost *>

ServerName [YOUR ACCOUNT].alwaysdata.net

# mod_wsgi WSGIScriptAlias / /home/[YOUR ACCOUNT]/www/myapp.wsgi

</VirtualHost>`

###

First, you have to create a file that will call your application and your application ... :

  1. myapp.wsgi whose the name already appears in the apache.log
  2. flask_app.py which will contains the core of your application

### Skeleton of myapp.wsgi

The path of the application is absent from the sys.path, so we have 2 different options, which will have an incidence on the rest of the application :

  1. append the path to sys.path
  2. or change the pwd to the directory of the path.

#-- encoding: utf8 --

import os import sys

#import site #site.addsitedir('/home/ze-egg2/mypymodules') #from werkzeug.debug import DebuggedApplication

#sys.path.append('.') #os.chdir('/home/[YOUR ACCOUNT]/www')

sys.path.append('/home/[YOUR ACCOUNT]/www/')

from flask_app import app as application

if __name__ == "__main__":
app.run()

### Skeleton of flask_app.py

We want to display the pwd and the path to verify the conf :

#-- encoding: utf8 --

import site # load the modules site.addsitedir('/home/[YOUR ACCOUNT]/mypymodules')

from flask import Flask app = Flask(__name__) app.debug = True

@app.route("/") def hello():

return "Hello World!"

@app.route("/pwd") def get_pwd():

from os import getcwd return 'Current direcory : ' + repr(getcwd())

@app.route("/path") def get_path():

from sys import path return 'sys.path : ' + repr(path)

### Display the last errors

You will often need to display the error that fired the proccess of your app:

tail ~/admin/log/error.log

### Checkout a new the app.py file which is going to be fired by mod_wsgi

If you want to create many different applications, you can create different a symbolink name whose to the target is myapp.wsgi.

ln -sf app.py myapp.wsgi

How to write a new app.py for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment