title: mod_wsgi (pid=2179): Target WSGI script '/opt/graphite/conf/graphite.wsgi' cannot be loaded as Python module
body: <p>I am working on AWS RHEL server.
  Getting this error each time I access the webpage(Webpage showing 500).</p>
  
  <p>Error.log:</p>
  
  <pre><code>[Sat Jul 09 02:51:12.736533 2016] [:error] [pid 2179] mod_wsgi (pid=2179): Target WSGI script '/opt/graphite/conf/graphite.wsgi' cannot be loaded as Python module.
  [Sat Jul 09 02:51:12.736572 2016] [:error] [pid 2179] mod_wsgi (pid=2179): Exception occurred processing WSGI script '/opt/graphite/conf/graphite.wsgi.
  [Sat Jul 09 02:51:12.736593 2016] [:error] [pid 2179] Traceback (most recent call last):
  [Sat Jul 09 02:51:12.736612 2016] [:error] [pid 2179]   File "/opt/graphite/conf/graphite.wsgi", line 14, in &lt;module&gt;
  [Sat Jul 09 02:51:12.736675 2016] [:error] [pid 2179]     from graphite.logger import log
  [Sat Jul 09 02:51:12.736685 2016] [:error] [pid 2179]   File "/opt/graphite/webapp/graphite/logger.py", line 84, in &lt;module&gt;
  [Sat Jul 09 02:51:12.736737 2016] [:error] [pid 2179]     log = GraphiteLogger() # import-shared logger instance
  [Sat Jul 09 02:51:12.736747 2016] [:error] [pid 2179]   File "/opt/graphite/webapp/graphite/logger.py", line 40, in __init__
  [Sat Jul 09 02:51:12.736762 2016] [:error] [pid 2179]     self.infoHandler = Rotater(self.infoLogFile,when="midnight",backupCount=1)
  [Sat Jul 09 02:51:12.736769 2016] [:error] [pid 2179]   File "/usr/lib64/python2.7/logging/handlers.py", line 169, in __init__
  [Sat Jul 09 02:51:12.737041 2016] [:error] [pid 2179]     BaseRotatingHandler.__init__(self, filename, 'a', encoding, delay)
  [Sat Jul 09 02:51:12.737056 2016] [:error] [pid 2179]   File "/usr/lib64/python2.7/logging/handlers.py", line 64, in __init__
  [Sat Jul 09 02:51:12.737073 2016] [:error] [pid 2179]     logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  [Sat Jul 09 02:51:12.737081 2016] [:error] [pid 2179]   File "/usr/lib64/python2.7/logging/__init__.py", line 902, in __init__
  [Sat Jul 09 02:51:12.737390 2016] [:error] [pid 2179]     StreamHandler.__init__(self, self._open())
  [Sat Jul 09 02:51:12.737401 2016] [:error] [pid 2179]   File "/usr/lib64/python2.7/logging/__init__.py", line 925, in _open
  [Sat Jul 09 02:51:12.737431 2016] [:error] [pid 2179]     stream = open(self.baseFilename, self.mode)
  [Sat Jul 09 02:51:12.737449 2016] [:error] [pid 2179] IOError: [Errno 13] Permission denied: '/opt/graphite/storage/log/webapp/info.log'
  </code></pre>
  
  <p>graphite.wsgi:</p>
  
  <pre><code>import os
  import sys
  sys.path.append('/opt/graphite/webapp')
  
  try:
      from importlib import import_module
  except ImportError:
      from django.utils.importlib import import_module
  
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'graphite.settings')  # noqa
  
  from django.conf import settings
  from django.core.wsgi import get_wsgi_application
  from graphite.logger import log
  
  application = get_wsgi_application()
  
  try:
  import whitenoise
  except ImportError:
     whitenoise = False
  else:
      # WhiteNoise &lt; 2.0.1 does not support Python 2.6
      if sys.version_info[:2] &lt; (2, 7):
          whitenoise_version = tuple(map(
                  int, getattr(whitenoise, '__version__', '0').split('.')))
          if whitenoise_version &lt; (2, 0, 1):
              whitenoise = False
  
  if whitenoise:
      from whitenoise.django import DjangoWhiteNoise
      application = DjangoWhiteNoise(application)
      prefix = "/".join((settings.URL_PREFIX.strip('/'), 'static'))
      for directory in settings.STATICFILES_DIRS:
          application.add_files(directory, prefix=prefix)
      for app_path in settings.INSTALLED_APPS:
          module = import_module(app_path)
          directory = os.path.join(os.path.dirname(module.__file__), 'static')
          if os.path.isdir(directory):
              application.add_files(directory, prefix=prefix)
  
  # Initializing the search index can be very expensive. The import below
  # ensures the index is preloaded before any requests are handed to  the
  # process.
  log.info("graphite.wsgi - pid %d - reloading search index" % os.getpid())
  import graphite.metrics.search  # noqa
  </code></pre>
  
  <p>graphite-vhost.conf(hosting it on port 8080):</p>
  
  <pre><code># This line also needs to be in your server's config.
   LoadModule wsgi_module modules/mod_wsgi.so
  
  # You need to manually edit this file to fit your needs.
  # This configuration assumes the default installation prefix
  # of /opt/graphite/, if you installed graphite somewhere else
  # you will need to change all the occurances of /opt/graphite/
  # in this file to your chosen install location.
  
  &lt;IfModule !wsgi_module.c&gt;
      LoadModule wsgi_module modules/mod_wsgi.so
  &lt;/IfModule&gt;
  
  # XXX You need to set this up!
  # Read http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGISocketPrefix
  WSGISocketPrefix /var/run/wsgi
  &lt;VirtualHost *:8080&gt;
          ServerName localhost
          DocumentRoot "/opt/graphite/webapp"
          ErrorLog /var/log/httpd/graphite_error.log
  #/opt/graphite/storage/log/webapp/error.log
          CustomLog /var/log/httpd/graphite_access.log combined
  #/opt/graphite/storage/log/webapp/access.log common
  
          # I've found that an equal number of processes &amp; threads tends
          # to show the best performance for Graphite (ymmv).
          WSGIDaemonProcess graphite processes=3 threads=5 display name='%{GROUP}' inactivity-timeout=120
          WSGIProcessGroup graphite
          WSGIApplicationGroup %{GLOBAL}
          WSGIImportScript /opt/graphite/conf/graphite.wsgi process-group=graphite application-group=%{GLOBAL}
  
          # XXX You will need to create this file! There is a graphite.wsgi.example
          # file in this directory that you can safely use, just copy it to graphite.wgsi
          WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi
  
      # XXX To serve static files, either:
      # django-admin.py collectstatic --noinput --settings=graphite.settings
      # * Install the whitenoise Python package (pip install whitenoise)
      # or
      # * Collect static files in a directory by running:
      #     django-admin.py collectstatic --noinput --settings=graphite.settings
      #   And set an alias to serve static files with Apache:
      Alias /content/ /opt/graphite/webapp/content/
      &lt;Location "/content/"&gt;
              SetHandler None
      &lt;/Location&gt;
  
      # XXX In order for the django admin site media to work you
      # must change @DJANGO_ROOT@ to be the path to your django
      # installation, which is probably something like:
      # /usr/lib/python2.6/site-packages/django
  
      Alias /media/ "/usr/lib/python2.7/site-packages/django/contrib/admin/media/"
      &lt;Location "/media/"&gt;
              SetHandler None
      &lt;/Location&gt;
  
      # The graphite.wsgi file has to be accessible by apache. It won't
      # be visible to clients because of the DocumentRoot though.
      &lt;Directory /opt/graphite/conf/&gt;
              Options All
              AllowOverride All
              Require all granted
              Order deny,allow
              Allow from all
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>I have chown /opt/graphite to apache. Still getting this error. Please help me out.</p>