Configure LAMPP with Django

70 views
Skip to first unread message

evstevemd

unread,
Jan 10, 2011, 10:56:10 AM1/10/11
to Django users
I have LAMPP on Ubuntu and I use it fine with PHP. Now I have to add
Django so that I can do PHP and Django projects together. I will have
more than one Django project. I have read of mod_wsgi but I cannot
understand. In PHP I just put my project as subdirectory of /var/www/
and then access them via http://localhost/
How do I do with Django?
Thanks a lot!

Javier Guerra Giraldez

unread,
Jan 10, 2011, 11:12:29 AM1/10/11
to django...@googlegroups.com
On Mon, Jan 10, 2011 at 10:56 AM, evstevemd <mwinj...@gmail.com> wrote:
> In PHP I just put my project as subdirectory of /var/www/
> and then access them via http://localhost/
> How do I do with Django?

Django is not a page-based template system like PHP. it's a
long-running application that answers web requests.

the difference means a much bigger separation between code and
presentation than in PHP, and implies a totally different deployment
architecture.

if you do the tutorials first, it will make all clear.

--
Javier

Thomas

unread,
Jan 10, 2011, 11:17:07 AM1/10/11
to django...@googlegroups.com

Am 10.01.2011 um 16:56 schrieb evstevemd:

> I have LAMPP on Ubuntu and I use it fine with PHP. Now I have to add
> Django so that I can do PHP and Django projects together. I will have
> more than one Django project. I have read of mod_wsgi but I cannot
> understand.

what exactly is the problem?

I found these explanations helpful:
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html

good luck


> In PHP I just put my project as subdirectory of /var/www/
> and then access them via http://localhost/
> How do I do with Django?
> Thanks a lot!
>

> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>

kRON

unread,
Jan 10, 2011, 8:19:22 PM1/10/11
to Django users
I wager that Javier already has the best possible answer, but,
nonetheless, I'll try to elaborate it a just a bit more.

When a client requests a resource from your Web server that's handled
by PHP, what happens is that an instance of PHP is fired that
initializes the request data in the globals (like $_POST, $_SERVER)
and sequentially creates a flattened view of your Web application code
necessary to handle that request.

Take PHP MVC frameworks as a good example. All of your requests (like
'/user/evstevemd/') get rewritten to `index.php?r=/user/evstevemd/`.
`index.php` includes a certain `routing.php` that then figures out
that all requests beginning with `/user/` are handled by a controller
that resides somewhere in `users/controllers.php` and so it includes
that, the code there includes something else and so forth until
there's no more code to execute. The fact remains that you also had
several dozens of other PHP files that were never executed, because
that code was never needed to process the particular request that was
received.

Django is a bit different, but that actually has everything do with
the nature of executing Python applications. To process requests that
Django needs to handle, your Web server will actually be communicating
with an instance of a Python interpreter, through the WSGI protocol.
WSGI is just a very small standard that practically says: because
every Web server that accepts HTTP requests has the liberty of
constructing and processing request data to their preferences, this is
the interface that defines how those requests should be passed to a
Python Web application.

Configuring PHP with your Web server is straightforward and it just
works OOTB instantaneously for all your PHP files. Although it's
execution model is simple and popular, if you acknowledge the
drawbacks there's a lot more to benefit from communicating with a long-
running Python process. First off the top is that after initialization
everything is already loaded into the memory, everything is
precomputed for future requests (such as URL routing) and all the
necessary connections to other parts of the system are created, so
subsequent requests become very cheap and are processed "blazingly"
fast.

I'm not an expert on the topic, but if you already have a LAMP stack,
what I'd do is set up nginx as a reverse proxy (approx. 30-ish lines
of code that's hard to get wrong) to your Apache Web server and a WSGI
server. You get the added benefit of not having to recompile/
reconfigure your Apache instance with mod_wsgi (which can easily be
misconfigured) and you can use a Python WSGI server such a Gunicorn or
Spawning that is more Pythonic (i.e. it works and understands Python
code better than mod_wsgi) to handle your Django Web applications.



On Jan 10, 5:17 pm, Thomas <tho...@googlemail.com> wrote:
> Am 10.01.2011 um 16:56 schrieb evstevemd:
>
> > I have LAMPP on Ubuntu and I use it fine with PHP. Now I have to add
> > Django so that I can do PHP and Django projects together. I will have
> > more than one Django project. I have read of mod_wsgi but I cannot
> > understand.
>
> what exactly is the problem?
>
> I found these explanations helpful:http://code.google.com/p/modwsgi/wiki/IntegrationWithDjangohttp://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django...
>
> good luck
>
> > In PHP I just put my project as subdirectory of /var/www/
> > and then access them viahttp://localhost/

Kenneth Gonsalves

unread,
Jan 11, 2011, 2:37:57 AM1/11/11
to django...@googlegroups.com
On Mon, 2011-01-10 at 11:12 -0500, Javier Guerra Giraldez wrote:
> Django is not a page-based template system like PHP. it's a
> long-running application that answers web requests.

I do not think it is a long running application
--
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://ilugcbe.techstud.org/

Javier Guerra Giraldez

unread,
Jan 11, 2011, 7:39:34 AM1/11/11
to django...@googlegroups.com
On Tue, Jan 11, 2011 at 2:37 AM, Kenneth Gonsalves
<law...@thenilgiris.com> wrote:
> On Mon, 2011-01-10 at 11:12 -0500, Javier Guerra Giraldez wrote:
>> Django is not a page-based template system like PHP.  it's a
>> long-running application that answers web requests.
>
> I do not think it is a long running application

'long' as compared to PHP processes, which are initialized and
destroyed for each HTTP request. Django, in contrast, stays up to
handle many requests.

--
Javier

evstevemd

unread,
Jan 11, 2011, 7:51:13 AM1/11/11
to Django users
Thanks friends,
I have learned alot in these few threads. Now my question was how do I
deploy different Django apps using same Apache server.
I tried instructions in links given above but I ended screwing my
Apache and ended falling back. May be my PHP background keeps me that
way.
Please help me and thanks!

Kenneth Gonsalves

unread,
Jan 11, 2011, 9:00:06 PM1/11/11
to django...@googlegroups.com

I do not think it does - django is not a webserver or server like zope
for example. So what does 'stays up' mean?

Kenneth Gonsalves

unread,
Jan 11, 2011, 9:02:16 PM1/11/11
to django...@googlegroups.com
On Tue, 2011-01-11 at 04:51 -0800, evstevemd wrote:
> I have learned alot in these few threads. Now my question was how do I
> deploy different Django apps using same Apache server.

use virtual hosts - one virtual host per project - and keep your
projects somewhere in the file system, each in it's own place (anywhere
except under /var/www/)

Javier Guerra Giraldez

unread,
Jan 12, 2011, 9:03:54 AM1/12/11
to django...@googlegroups.com
On Tue, Jan 11, 2011 at 9:00 PM, Kenneth Gonsalves
<law...@thenilgiris.com> wrote:
> I do not think it does - django is not a webserver or server like zope
> for example. So what does 'stays up' mean?

it is. depending on how you deploy, it's a FastCGI server, or a WSGI server.

in any case, the process is started once, lots of initializations are
done, and it starts receiving user's requests (after some translations
from the frontend web server). If you modify non-local resources in
memory, they are available for the next request.

Of course, most schemas start more than one process or thread, and you
never know which one will service the next request, so you can't rely
on that being available. Still, it's the base of the 'memory' cache
backend: simply a global Python variable that holds data from previous
requests.

Another complication is that usually there's a request counter, and
after it goes to zero, the thread/process is killed and another one is
started. That's usually done to limit any memory leak or similar
degradation, but it's done after several (sometimes hundreds of)
requests, not for each and every one like on PHP.

Why is that important? because all the models and urls and similar
scaffolding are done once and used afterwards. If you do funny things
there and/or don't take in account the lazy nature of Querysets, you
might see some strange things happening.

At the same time, it means Django is free of the "the most classes you
initialize, the slower your app is" effect in PHP.

--
Javier

evstevemd

unread,
Jan 13, 2011, 6:43:31 AM1/13/11
to Django users
I love this,
any tutorial on how to create virtual hosts?

Kenneth Gonsalves

unread,
Jan 13, 2011, 7:06:39 AM1/13/11
to django...@googlegroups.com
On Thu, 2011-01-13 at 03:43 -0800, evstevemd wrote:
> I love this,
> any tutorial on how to create virtual hosts?

django documentation, in the deployment section shows how

evstevemd

unread,
Jan 13, 2011, 8:04:23 AM1/13/11
to Django users
thanks, let me check

On Jan 13, 3:06 pm, Kenneth Gonsalves <law...@thenilgiris.com> wrote:
> On Thu, 2011-01-13 at 03:43 -0800, evstevemd wrote:
> > I love this,
> > any tutorial on how to create virtual hosts?
>
> django documentation, in the deployment section shows how
> --
> regards
Reply all
Reply to author
Forward
0 new messages