2

I'm unable to deploy my django site using mod_wsgi after a a few frustrating days of trying. Could someone sanity check these details and see if there's anything obviously wrong? This is my first Django deployment. Its been running file with python manage.py runserver 10.10.10.214:8080 but I cannot deploy

my wsgi.py file in /home/user/django/mysite (also where my settings.py etc are)

"""
WSGI config for myproject project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
"""

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

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

my apache .conf file:

LoadModule wsgi_module /home/conf/apache2/modules/mod_wsgi.so #dont read into the locations too much - they are correct

WSGIScriptAlias / /home/user/django/mysite/wsgi.py
WSGIPythonPath /home/user/django

<Directory /home/user/django/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

I am forced to use a heavily pre-customized version of apache but the conf file above is included. Any help at all would be great.

Cheers, Arthur

12
  • I recommend to deploy with nginx and uwsgi ;) django-tips.com/tip/… Commented Jul 1, 2015 at 16:44
  • 1
    Does the apache error log point you in any direction. The config seems about right at first glance Commented Jul 1, 2015 at 16:48
  • I might just have to look at that @doniyor Commented Jul 1, 2015 at 16:48
  • 1
    This could also help: askubuntu.com/questions/451922/… Commented Jul 1, 2015 at 17:05
  • 1
    A home directory such as /home/user would often have restrictive permissions and not be accessible to other users. Thus it isn't enough just to make the Django project directory accessible. The home directory would also need to be accessible to the user that Apache runs as. It may be better to move the project out of your user account so you aren't mucking with the account permissions. Commented Jul 2, 2015 at 1:26

1 Answer 1

2

Try this wsgi.py:

import os
import sys

os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"

sys.path.append('/home/user/django/mysite/')
sys.path.append('/home/user/django/')

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

And add this to your conf, before the alias:

WSGIDaemonProcess <process_name> processes=2 threads=15 user=<username> display-name=%{GROUP}
WSGIProcessGroup <process_name>

The process name could be "mysite.com" or whatever. The user is a Linux user.

Sign up to request clarification or add additional context in comments.

2 Comments

Rob - would I be correct in saying that the <process_name> can be anything? Something logical of course. Also I believe leaving user=<username> out will use default apache child permissions
Arthur, you're probably right about both of those things. I use user=www-data, for example.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.