apache gets confused with difference between dev and production version of site

3 views
Skip to first unread message

delfick755

unread,
Nov 3, 2009, 12:14:15 AM11/3/09
to Django users
Hello,

I have a setup where a django's debug setting is changed depending on
whether os.environ['PRODUCTION'] is true or false.

Which means when I setup apache, I do "SetEnv PRODUCTION true" to mark
a site as production.

I then have /etc/hosts setup so that http://home and http://cec point
to localhost.

Then in apache I have dev versions of my two sites (home and cec) as
follows
http://pastebin.com/m56aab2f1 and http://pastebin.com/m537594e6

This works fine. However I also want it so when people access my
computer from outside (i.e. http://delfick.servehttp.com) then debug
isn't turned on. For this I have
http://pastebin.com/m28abffd5

This also works fine.

However it seems this solution isn't a very good one and it will
alternate between versions. so if I refresh http://cec then sometimes
it's the production version, sometimes development version and same
for http://delfick.servehttp.com.

is there a way to get around this or will I just have to create copies
of the sites to be used for the production version?

Thankyou

Regards
Stephen

Graham Dumpleton

unread,
Nov 3, 2009, 12:21:59 AM11/3/09
to Django users
Which of the many ways of hosting under Apache are you using?

mod_python? mod_wsgi? mod_fcgid? mod_fastcgi? mod_cgi(d)? mod_scgi?
other?

SetEnv does not set os.environ in a number of these.

Graham

On Nov 3, 4:14 pm, delfick755 <delfick...@gmail.com> wrote:
> Hello,
>
> I have a setup where a django's debug setting is changed depending on
> whether os.environ['PRODUCTION'] is true or false.
>
> Which means when I setup apache, I do "SetEnv PRODUCTION true" to mark
> a site as production.
>
> I then have /etc/hosts setup so thathttp://homeandhttp://cecpoint
> to localhost.
>
> Then in apache I have dev versions of my two sites (home and cec) as
> followshttp://pastebin.com/m56aab2f1andhttp://pastebin.com/m537594e6
>
> This works fine. However I also want it so when people access my
> computer from outside  (i.e.http://delfick.servehttp.com) then debug
> isn't turned on. For this I havehttp://pastebin.com/m28abffd5
>
> This also works fine.
>
> However it seems this solution isn't a very good one and it will
> alternate between versions. so if I refreshhttp://cecthen sometimes
> it's the production version, sometimes development version and same
> forhttp://delfick.servehttp.com.

Graham Dumpleton

unread,
Nov 3, 2009, 12:28:12 AM11/3/09
to Django users
Sorry, I should just follow your pastebin links shouldn't I. :-)

On Nov 3, 4:21 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:

Graham Dumpleton

unread,
Nov 3, 2009, 12:31:57 AM11/3/09
to Django users
Arrgh, pressed send to quick.

Read:

http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Application_Environment_Variables

You are experiencing environment variable leakage between Python sub
interpreters. Affects mod_wsgi as well as mod_python, or any embedded
solution using multiple Python interpreters for that matter.

Make sure you set PRODUCTION/INTERNET in all application
configurations. Ie., add:

SetEnv PRODUCTION true
SetEnv INTERNET true

or whatever it needs to be in other configurations.

Graham

On Nov 3, 4:28 pm, Graham Dumpleton <graham.dumple...@gmail.com>

Stephen Moore

unread,
Nov 3, 2009, 12:49:07 AM11/3/09
to django...@googlegroups.com
On Tue, Nov 3, 2009 at 1:31 PM, Graham Dumpleton
<graham.d...@gmail.com> wrote:
> http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Application_Environment_Variables
>
> You are experiencing environment variable leakage between Python sub
> interpreters. Affects mod_wsgi as well as mod_python, or any embedded
> solution using multiple Python interpreters for that matter.

ahhhh....

that makes sense :)

>
> Make sure you set PRODUCTION/INTERNET in all application
> configurations. Ie., add:
>
>        SetEnv PRODUCTION true
>        SetEnv INTERNET true
>
> or whatever it needs to be in other configurations.

hmm, I'm not sure if that solves the problem or not.
It seems less frequent but it does happen.....

is there a way to pass options to the site with mod_python without
relying on environment variables?

Regards
Stephen

Graham Dumpleton

unread,
Nov 3, 2009, 1:31:03 AM11/3/09
to Django users


On Nov 3, 4:49 pm, Stephen Moore <delfick...@gmail.com> wrote:
> On Tue, Nov 3, 2009 at 1:31 PM, Graham Dumpleton
>
> <graham.dumple...@gmail.com> wrote:
> >http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Application_E...
>
> > You are experiencing environment variable leakage between Python sub
> > interpreters. Affects mod_wsgi as well as mod_python, or any embedded
> > solution using multiple Python interpreters for that matter.
>
> ahhhh....
>
> that makes sense :)
>
>
>
> > Make sure you set PRODUCTION/INTERNET in all application
> > configurations. Ie., add:
>
> >        SetEnv PRODUCTION true
> >        SetEnv INTERNET true
>
> > or whatever it needs to be in other configurations.
>
> hmm, I'm not sure if that solves the problem or not.
> It seems less frequent but it does happen.....
>
> is there a way to pass options to the site with mod_python without
> relying on environment variables?

Cant you just have different settings files and set
DJANGO_SETTINGS_MODULES different for each installation?

Graham

Stephen Moore

unread,
Nov 3, 2009, 1:55:13 AM11/3/09
to django...@googlegroups.com
On Tue, Nov 3, 2009 at 2:31 PM, Graham Dumpleton
<graham.d...@gmail.com> wrote:
> Cant you just have different settings files and set
> DJANGO_SETTINGS_MODULES different for each installation?
>

The problem with that becomes let's say I have the two options
production and internet, then that means that I have to have 4
different settings.py for each combination.

I did find an interesting idea here
http://www.modpython.org/pipermail/mod_python/2006-June/021316.html
just then.

basically you modify PythonPath depending on what features you want.

For example, say I have a file hierarchy like so

options/
debug/
production/
__init__.py
apacheSettings.py
#In here set PRODUCTION=True

dev/
__init__.py
apacheSettings.py
#In here set PRODUCTION=False

internet/
on/
__init__.py
apacheSettings.py
#In here set INTERNET=True

off/
__init__.py
apacheSettings.py
#In here set INTERNET=False

then in settings.py

PRODUCTION = True
try:
import apacheSettings
PRODUCTION = apacheSettings.PRODUCTION
except ImportError:
pass


INTERNET = True
try:
import internetSettings
INTERNET = internetSettings.INTERNET
except ImportError:
pass

and finally, in apache configuration


PythonPath " \
[ \
'/home/iambob/web/options/debug/production', \
'/home/iambob/web/options/internet/on', \
'/home/iambob/web', '/home/iambob/web/common', '/home/iambob/web/home'\
] + sys.path"

or

PythonPath " \
[ \
'/home/iambob/web/options/debug/dev', \
'/home/iambob/web/options/internet/off', \
'/home/iambob/web', '/home/iambob/web/common', '/home/iambob/web/home'\
] + sys.path"

which seems to work rather nicely

:)

Graham Dumpleton

unread,
Nov 3, 2009, 2:00:20 AM11/3/09
to Django users


On Nov 3, 5:55 pm, Stephen Moore <delfick...@gmail.com> wrote:
> On Tue, Nov 3, 2009 at 2:31 PM, Graham Dumpleton
>
> <graham.dumple...@gmail.com> wrote:
> > Cant you just have different settings files and set
> > DJANGO_SETTINGS_MODULES different for each installation?
>
> The problem with that becomes let's say I have the two options
> production and internet, then that means that I have to have 4
> different settings.py for each combination.
>
> I did find an interesting idea herehttp://www.modpython.org/pipermail/mod_python/2006-June/021316.html
All I can suggest is get rid of mod_python. It is a fair bit simpler
in mod_wsgi to do these sorts of per setup overrides because the WSGI
script file acts as an intermediary from which overrides can be
applied.

Graham

delfick755

unread,
Nov 3, 2009, 2:03:37 AM11/3/09
to Django users


On Nov 3, 3:00 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
fair enough.

I'll look into that one day.

Thankyou very much for your help :)

Stephen Moore

unread,
Nov 3, 2009, 3:10:01 AM11/3/09
to Django users
well, my solution wasn't working still...

so more research has finally led me to the real problem.

http://docs.djangoproject.com/en/dev/howto/deployment/modpython/

I had the PythonInterpreter setting in the apache configurations to
the same value. Changing it to a different value for the production
and development versions solved the problem :)

Reply all
Reply to author
Forward
0 new messages