# apache wsgi problem

## royalts

Hey!

I have a django project which I tried to port using apache2 (Apache itself works very well on my computer). I worked through this tutorial: https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04 without create the django project. 

When I tried to run my project I got the following error:

 *Quote:*   

> 
> 
> 500 Internal Server Error
> 
> The server encountered an internal error or misconfiguration and was unable to complete your request.
> ...

 

/var/log/apache2/error_log showed up this:

```

[Sat May 14 23:22:34.114802 2016] [mpm_event:notice] [pid 20112:tid 140379044435840] AH00491: caught SIGTERM, shutting down

[Sat May 14 23:22:35.255662 2016] [mpm_event:notice] [pid 20415:tid 140403653846912] AH00489: Apache/2.4.18 (Unix) OpenSSL/1.0.2h PHP/5.6.21-pl0-gentoo mod_wsgi/4.4.21 Python/2.7.10 configured -- resuming normal operations

[Sat May 14 23:22:35.255738 2016] [core:notice] [pid 20415:tid 140403653846912] AH00094: Command line: '/usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D PHP5 -D FTPD -D WSGI -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf'

[Sat May 14 23:22:44.785454 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52] mod_wsgi (pid=20417): Target WSGI script '/var/www/localhost/htdocs/django/stundenplan/stundenplan/wsgi.py' cannot be loaded as Python module.

[Sat May 14 23:22:44.785497 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52] mod_wsgi (pid=20417): Exception occurred processing WSGI script '/var/www/localhost/htdocs/django/stundenplan/stundenplan/wsgi.py'.

[Sat May 14 23:22:44.785522 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52] Traceback (most recent call last):

[Sat May 14 23:22:44.785547 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]   File "/var/www/localhost/htdocs/django/stundenplan/stundenplan/wsgi.py", line 16, in <module>

[Sat May 14 23:22:44.785633 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]     application = get_wsgi_application()

[Sat May 14 23:22:44.785647 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]   File "/usr/lib64/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application

[Sat May 14 23:22:44.785686 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]     django.setup()

[Sat May 14 23:22:44.785698 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]   File "/usr/lib64/python3.4/site-packages/django/__init__.py", line 18, in setup

[Sat May 14 23:22:44.785732 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]     apps.populate(settings.INSTALLED_APPS)

[Sat May 14 23:22:44.785742 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]   File "/usr/lib64/python3.4/site-packages/django/apps/registry.py", line 85, in populate

[Sat May 14 23:22:44.785850 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]     app_config = AppConfig.create(entry)

[Sat May 14 23:22:44.785861 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]   File "/usr/lib64/python3.4/site-packages/django/apps/config.py", line 112, in create

[Sat May 14 23:22:44.785921 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]     mod = import_module(mod_path)

[Sat May 14 23:22:44.785932 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]   File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module

[Sat May 14 23:22:44.785971 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]     __import__(name)

[Sat May 14 23:22:44.785981 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]   File "/usr/lib64/python3.4/site-packages/django/contrib/auth/apps.py", line 7, in <module>

[Sat May 14 23:22:44.786014 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]     from .management import create_permissions

[Sat May 14 23:22:44.786024 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]   File "/usr/lib64/python3.4/site-packages/django/contrib/auth/management/__init__.py", line 12, in <module>

[Sat May 14 23:22:44.786078 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]     from django.core.management.base import CommandError

[Sat May 14 23:22:44.786088 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]   File "/usr/lib64/python3.4/site-packages/django/core/management/__init__.py", line 16, in <module>

[Sat May 14 23:22:44.786174 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]     from django.utils import autoreload, lru_cache, six

[Sat May 14 23:22:44.786184 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]   File "/usr/lib64/python3.4/site-packages/django/utils/autoreload.py", line 62, in <module>

[Sat May 14 23:22:44.786266 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]     import pyinotify

[Sat May 14 23:22:44.786277 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]   File "/usr/lib64/python3.4/site-packages/pyinotify.py", line 53, in <module>

[Sat May 14 23:22:44.786623 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52]     raise UnsupportedPythonVersionError(sys.version)

[Sat May 14 23:22:44.786644 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52] UnsupportedPythonVersionError: Python 2.7.10 (default, Nov 18 2015, 09:59:53) 

[Sat May 14 23:22:44.786648 2016] [wsgi:error] [pid 20417:tid 140403439646464] [remote ::1:52] [GCC 4.9.3] is unsupported, requires at least Python 3.0

```

So obviously python 2.7 comes into play but my official interpreter is python 3.4:

```

  [1]   python2.7

  [2]   python3.4 *

```

and gcc 4.9.3. isn't installed either:

```

 [1] x86_64-gentoo-linux-gnu-5.3.0 *

 [2] x86_64-pc-linux-gnu-5.3.0 *

```

So what is calling python 2.7?

my /etc/apache2/vhosts.d/00_default_vhost.conf:

```

....

<VirtualHost *:80>

   ServerName localhost

   Include /etc/apache2/vhosts.d/default_vhost.include

   <IfModule mpm_peruser_module>

      ServerEnvironment apache apache

   </IfModule>

    ServerAlias /static /var/www/localhost/htdocs/django/stundenplan/static/

    <Directory /var/www/localhost/htdocs/django>

        Require all granted

    </Directory>

    <Directory /var/www/localhost/htdocs/django/stundenplan/stundenplan/>

        <Files wsgi.py>

            Require all granted

        </Files>

    </Directory>

    WSGIDaemonProcess stundenplan python-path=/var/www/localhost/htdocs/django/stundenplan:/usr/lib64/python3.4/site-packages

    WSGIProcessGroup stundenplan

    WSGIScriptAlias / /var/www/localhost/htdocs/django/stundenplan/stundenplan/wsgi.py

</VirtualHost>

</IfDefine>

```

and my wsgi.py:

```

"""

WSGI config for stundenplan 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.8/howto/deployment/wsgi/

"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "stundenplan.settings")

application = get_wsgi_application()

```

equery uses www-apache/mod_wsgi showd up:

```

[ Legend : U - final flag setting for installation]

[        : I - package is installed with flag     ]

[ Colors : set, unset                             ]

 * Found these USE flags for www-apache/mod_wsgi-4.4.21:

 U I

 + + python_single_target_python2_7 : Build for Python 2.7 only

 - - python_single_target_python3_3 : Build for Python 3.3 only

 - - python_single_target_python3_4 : Build for Python 3.4 only

 + + python_targets_python2_7       : Build with Python 2.7

 - - python_targets_python3_3       : Build with Python 3.3

 + + python_targets_python3_4       : Build with Python 3.4

```

Is " python_single_target_python2_7" the failure? I can't remeber set this variable? where is it come from?

kind regards

----------

## royalts

yeah... that solved the problem... thanks 4 reading  :Smile: 

----------

