title: 403 error on Apache Server with Django application
body: <p>I've been searching throughout this site for a solution but haven't been able to find one.  I have a CentOS 6.4 server with Apache 2.2.15, Django 1.6 and mod_wsgi 3.2.  I am using Apache to display static files and mod_wsgi to display Django content. </p>
  
  <p>I placed the Django project files in the <code>/srv</code> directory due to <a href="https://stackoverflow.com/questions/2894611/safely-hosting-a-django-project-over-apache-using-centos">this page</a>.</p>
  
  <p>When I run the Django development server, the test page that I wrote up displays properly.  However, when I start my Apache server and visit 127.0.0.1, I get a 403 Forbidden error.</p>
  
  <p><strong>django.wsgi</strong> (in /srv/mysite)</p>
  
  <pre><code>import os
  import sys
  
  envpath = '/usr/lib/python2.6/site-packages'
  
  pwd = os.path.dirname(os.path.abspath(__file__))
  os.chdir(pwd)
  sys.path = [env] + sys.path
  
  os.environ['PYTHON_EGG_CACHE'] = '/srv/mysite/.python-egg'
  os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
  
  site.addsitedir(envpath)
  
  from django.core.handlers.wsgi import WSGIHandler
  application = WSGIHandlers()
  </code></pre>
  
  <p><strong>httpd.conf</strong></p>
  
  <pre><code>WSGIScriptAlias / /srv/mysite/django.wsgi
  WSGIPythonPath /srv/mysite
  &lt;more aliases and tags in order to get the right static files to show&gt;
  </code></pre>
  
  <p>In the <code>httpd.conf</code> file, the user and group that is listed is the default <code>apache</code>.  I ran a <code>ls -l</code> on the <code>/srv</code> directory and its owner and group were listed as <code>root</code>.  So, I ran <code>sudo chown -R apache:apache /srv/mysite</code> which changed the directory and all subdirectories to use <code>apache</code> as owner and group.</p>
  
  <p>However, no matter how much I Google or try, I can't get over this 403 error.  </p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>I've discovered that when I disable SELinux, and the <code>WSGIPythonPath</code> variable in the <code>http.conf</code> file is <code>django.wsgi</code>, it results in a 500 Internal Server error.  However, when I change it to <code>wsgi.py</code>, my website displays properly.  I am curious as to why that is.</p>
  
  <p>In any case, since this will be a production machine, I prefer to keep SELinux on and figure out how to get the appropriate permissions figured out.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I've edited my <code>django.wsgi</code> file (changed above) ala <a href="https://stackoverflow.com/questions/9353092/could-not-import-settings-myproject-settings-is-it-on-sys-path-no-module-n">this link</a></p>
  
  <p><strong>EDIT 3:</strong></p>
  
  <p>I tried moving my project files into the my /home/ folder.  I've been alternating between trying <code>django.wsgi</code> and <code>wsgi.py</code> but still can't get past the 403 Forbidden error.  I thought it was originally a permissions issue with the <code>/srv</code> directory but it appears that's not the case...I am trying to figure this out but nothing is working.</p>
  
  <p><strong>EDIT 4:</strong></p>
  
  <p>I decided to just stick the development server for now...but I still need to get this working and I am at the end of my rope.  Is there anyone out there that can help me?</p>