Error when serve Django 1.8 Applications with Apache2 and mod_wsgi on Ubuntu 14.04
Question: I am trying to serve my django project with Apache2 and mod_wsgi and I am
stuck. Everything works fine until I try to integrate mod_wsgi. I am using
python 3. The relevant coding are as below:

* * *

## Apache2.conf

    
    
    <VirtualHost *:80>
            ServerAdmin myemail@example.com
            ServerName example.com
            ServerAlias www.example.com
    
            DocumentRoot /var/www/mysite
    
            Alias /static/ /var/www/mysite/static/
    
            <Directory /var/www/mysite/static>
            Require all granted
            </Directory>
    
    
            WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
    
    
            <Directory /var/www/mysite/mysite/wsgi.py>
            <Files wsgi.py>
            Require all granted
            </Files>
            </Directory>
    
            # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
            # error, crit, alert, emerg.
            # It is also possible to configure the loglevel for particular
            # modules, e.g.
            #LogLevel info ssl:warn
    
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
    
            # For most configuration files from conf-available/, which are
            # enabled or disabled at a global level, it is possible to
            # include a line for only one particular virtual host. For example the
            # following line enables the CGI configuration for this host only
            # after it has been globally disabled with "a2disconf".
            #Include conf-available/serve-cgi-bin.conf
    </VirtualHost>
    

* * *

## wsgi.py

    
    
    import os
    
    from django.core.wsgi import get_wsgi_application
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    
    application = get_wsgi_application()
    

* * *

## Error log

    
    
    [Mon Aug 03 18:45:42.192589 2015] [:error] [pid 2638:tid 140604829079296] [client 130.102.158.21:49084]   File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
    [Mon Aug 03 18:45:42.192606 2015] [:error] [pid 2638:tid 140604829079296] [client 130.102.158.21:49084]   File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
    [Mon Aug 03 18:45:42.192623 2015] [:error] [pid 2638:tid 140604829079296] [client 130.102.158.21:49084]   File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
    [Mon Aug 03 18:45:42.192649 2015] [:error] [pid 2638:tid 140604829079296] [client 130.102.158.21:49084] ImportError: No module named 'mysite'
    

* * *

I know it has something to do with how wsgi was configured in apache2.conf
file, but have no idea how to fix it. Any help would be appreciated. Thanks


Answer: You need to add this:

    
    
    WSGIPythonPath /var/www/mysite
    

From the
[doc](https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/),
_"The WSGIPythonPath line ensures that your project package is available for
import on the Python path; in other words, that import mysite works."_

