[ELI5] how to deploy django

165 views
Skip to first unread message

Walter Wang

unread,
Mar 3, 2014, 10:36:06 PM3/3/14
to django...@googlegroups.com
 I tried my best to follow the various guides out there, but the official documentation here https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/ has different instructions than the instructions here, https://www.digitalocean.com/community/articles/using-mod_wsgi-to-serve-applications-on-ubuntu-12-04

I have been at this for over a week now, and I can't figure out how to deploy django with mod_wsgi and apache on a linux web server.

Can someone give or point to me a step to step instruction on how to deploy django?

Specifically,
1. what do I do with the httpd.conf file?
2. wsgi file? what's the difference between "making a wsgi file" and a wsgi.py file? For example


"wsgi file"

import os
import sys	
sys.path.append('~/public_html/domain1.com/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'MyTestProject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()


"wsgi.py"

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mywebsite.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Thank you for any help.

Sam Lai

unread,
Mar 4, 2014, 2:28:04 AM3/4/14
to django-users
On 4 March 2014 14:36, Walter Wang <mr.wal...@gmail.com> wrote:
> I tried my best to follow the various guides out there, but the official
> documentation here
> https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/ has
> different instructions than the instructions here,
> https://www.digitalocean.com/community/articles/using-mod_wsgi-to-serve-applications-on-ubuntu-12-04

Follow the digitalocean instructions. The official Django
documentation assumes you are across Apache and how mod_wsgi works in
general, and therefore doesn't give step-by-step instructions.

> I have been at this for over a week now, and I can't figure out how to
> deploy django with mod_wsgi and apache on a linux web server.
>
> Can someone give or point to me a step to step instruction on how to deploy
> django?
>
> Specifically,
> 1. what do I do with the httpd.conf file?

Follow the digitalocean instructions and don't touch this file (for
reference, it is referring to /etc/apache2/httpd.conf).

> 2. wsgi file? what's the difference between "making a wsgi file" and a
> wsgi.py file?

They're the same thing. mod_wsgi doesn't care what the extension is.
The content in your two examples is slightly different as one was
written for an older version of Django.

If you're still stuck, you'll need to provide more details like -
Linux distribution and version, Django version, Apache version, path
to project, virtual host file contents, the output when you use the
'wget' command to visit the website, and also anything in the Apache
log files.

Daniel Roseman

unread,
Mar 4, 2014, 4:42:55 AM3/4/14
to django...@googlegroups.com
On Tuesday, 4 March 2014 07:28:04 UTC, Sam Lai wrote:
On 4 March 2014 14:36, Walter Wang <mr.wal...@gmail.com> wrote:
>  I tried my best to follow the various guides out there, but the official
> documentation here
> https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/ has
> different instructions than the instructions here,
> https://www.digitalocean.com/community/articles/using-mod_wsgi-to-serve-applications-on-ubuntu-12-04

Follow the digitalocean instructions.

I don't necessarily agree. The digitalocean instructions seem to be for Django version 1.4 (annoyingly, they don't specify which version it applies to, and don't even put a year on the datestamp of the article). Various changes have been made to the default configuration of Django since then. The OP needs to specify which version of Django they are using.

In any case, the digitalocean instructions are simply wrong in at least one important detail: you should not put your Django code under /public_html.
--
DR.

Alan Hicks

unread,
Mar 4, 2014, 7:15:45 AM3/4/14
to django...@googlegroups.com
On 04/03/2014 03:36, Walter Wang wrote:
> I tried my best to follow the various guides out there, but the
> official documentation here
> https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/ has
> different instructions than the instructions here,
> https://www.digitalocean.com/community/articles/using-mod_wsgi-to-serve-applications-on-ubuntu-12-04
+1 for official documents, assuming you are using Django 1.6

Good clear guidance on mod_wsgi with Apache
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/

Good guidance on wsgi if a little verbose
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/

>
>
> I have been at this for over a week now, and I can't figure out how to
> deploy django with mod_wsgi and apache on a linux web server.
>
> Can someone give or point to me a step to step instruction on how to
> deploy django?
>
> Specifically,
> 1. what do I do with the httpd.conf file?
> 2. wsgi file? what's the difference between "making a wsgi file" and a
> wsgi.py file? For example
As per the docs for version 1.6 it is wsgi.py

>
> "wsgi file"
>
> import os
> import sys
> sys.path.append('~/public_html/domain1.com/')
> os.environ['DJANGO_SETTINGS_MODULE'] = 'MyTestProject.settings'
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
Your project is named MyTestProject.settings here

>
> "wsgi.py"
>
> import os
> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mywebsite.settings")
Your project is named mywebsite.settings here

>
> from django.core.wsgi import get_wsgi_application
> application = get_wsgi_application()
>
> Thank you for any help.

Perhaps you renamed part of your project?
If your project is named mywebsite located at /usr/local/www/domain1.com
then the wsgi.py file should contain something like the following six lines:

import os
import sys
sys.path.append('/usr/local/www/domain1.com')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mywebsite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Alan

Walter Wang

unread,
Mar 4, 2014, 11:53:32 AM3/4/14
to django...@googlegroups.com
Thanks alot for all your answers, I really appreciate it.

I am using ubuntu 12.04 lts hosted on digitalocean. Apache version is 2.2.2 and django is 1.6, I created a virtualenv in the home directory, named myproject, I am using python3.2 as the interpreter in the virtualenv.

All your answers has given renewed energy.

So from reading all your answers, based on having django 1.6. I should edit the wsgi.py file and I don't have to make a "wsgi file" according to the digital ocean instructions.

What about the httpd.conf file? According to sam I should not touch it, but the official documentation for 1.6 says otherwise.

Daniel Roseman

unread,
Mar 4, 2014, 2:07:29 PM3/4/14
to django...@googlegroups.com
No, in Debian-based distributions like Ubuntu, the specific configuration for each virtual host is in the sites-available directory. Follow the DigitalOcean instructions for that part, except that the WSGIScriptAlias should point to your existing wsgi.py file, which you should not need to edit.
--
DR.

voger

unread,
Mar 4, 2014, 3:03:17 PM3/4/14
to django...@googlegroups.com
Hi, I am using Debian Wheezy and this is my configuration. This is the
content of /etc/apache2/sites-available/mysitedomain.com. I made this
file following the official django docs.

Keep in mind that this is a deployed for testing purposes site so both
static files and django files are served from the same server, against
django guidelines. I am posting it here just to give you an example.

I am using the wsgi.py file created by startproject and I don't know if
I can keep it when I go live. For that maybe we can get some experienced
advice.

Also I had to rename the /etc/apache2/sites-available/default.<whatever>
to default.bak so apache wouldn't default to that.

No need for httpd.conf file. I couldn't find any in my server anyway.

The project is named ssite and the projects folder is simply it's parent
folder.

Hope this helps

Alias /robots.txt /home/voger/projects/ssite/static/robots.txt
Alias /favicon.ico /home/voger/projects/ssite/static/favicon.ico

AliasMatch ^/([^/]*\.css) /home/voger/projects/ssite/static/styles/$1

Alias /media/ /home/voger/projects/ssite/media/
Alias /static/ /home/voger/projects/ssite/static/

<Directory /home/voger/projects/ssite/static>
Order deny,allow
Allow from All
</Directory>

<Directory /home/voger/projects/ssite/media>
Order deny,allow
Allow from All
</Directory>

WSGIDaemonProcess mysitedomain.com
python-path=/home/voger/projects/ssite:/home/voger/ssite_venv/lib/python2.7/site-packages
WSGIProcessGroup mysitedomain.com

WSGIScriptAlias / /home/voger/projects/ssite/ssite/wsgi.py

<Directory /home/voger/projects/ssite/ssite>
<Files wsgi.py>
Order allow,deny
Allow from All
</Files>



Sells, Fred

unread,
Mar 18, 2014, 3:42:03 PM3/18/14
to django...@googlegroups.com

The latest “Two Scoops of Django” book claims to have good info on deploying; I’ve not read it yet.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2728636a-1b69-4836-b5f4-bb95c89f39ea%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages