2

I am using an Ubuntu 14.10 X86_64 system with softwares in below:

  • python 3.4
  • apache2
  • libapache2-mod-wsgi-py3
  • django1.8

I created a project by django1.8 at this path:

/var/www/html/koorimeo

I've noticed that django-admin startproject will generate a wsgi.py file by default and I haven't change its content.

I configured apache2 under the official document(How to use Django with Apache and mod_wsgi) details:

I modified 000-default.conf for I don't want to setup another Virtual Host. and This is What I added:

#000-default.conf
<VirtualHost *:80>
...
<Directory /var/www/html/koorimeo/koorimeo>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>
...
</VirtualHost>

After that I declare WSGIAlias and WSGIPythonPath in apache2.conf:

#apache2.conf
#I want to leave "/" for other use...
WSGIScriptAlias /koorimeo /var/www/html/koorimeo/koorimeo/wsgi.py
WSGIPythonPath /var/www/html/koorimeo/koorimeo

After finished setting files I restarted apache2 service and login into 127.0.0.1/koorimeo, it returned a 500 error message... I looked up the error log file and get these error message:

bing@k-lab:/var/log/apache2$ tail error.log
[Sat Apr 25 14:35:31.214661 2015] [:notice] [pid 16997:tid 140004070725504] mod_python: Creating 8 session mutexes based on 6 max processes and 25 max threads.
[Sat Apr 25 14:35:31.214705 2015] [:notice] [pid 16997:tid 140004070725504] mod_python: using mutex_directory /tmp 
[Sat Apr 25 14:35:31.232634 2015] [:warn] [pid 16997:tid 140004070725504] mod_wsgi: Compiled for Python/3.4.0.
[Sat Apr 25 14:35:31.232682 2015] [:warn] [pid 16997:tid 140004070725504] mod_wsgi: Runtime using Python/2.7.6.
[Sat Apr 25 14:35:31.232766 2015] [mpm_event:notice] [pid 16997:tid 140004070725504] AH00489: Apache/2.4.7 (Ubuntu) mod_python/3.3.1 Python/2.7.6 mod_wsgi/3.4 configured -- resuming normal operations
[Sat Apr 25 14:35:31.232786 2015] [core:notice] [pid 16997:tid 140004070725504] AH00094: Command line: '/usr/sbin/apache2'
[Sat Apr 25 14:35:32.234958 2015] [core:notice] [pid 16997:tid 140004070725504] AH00051: child pid 18325 exit signal Aborted (6), possible coredump in /etc/apache2
[Sat Apr 25 14:35:32.235070 2015] [core:notice] [pid 16997:tid 140004070725504] AH00051: child pid 18326 exit signal Aborted (6), possible coredump in /etc/apache2
[Sat Apr 25 14:35:34.041184 2015] [:error] [pid 18599:tid 140003960342272] [client 127.0.0.1:51134] mod_wsgi (pid=18599): Target WSGI script '/var/www/html/koorimeo/koorimeo/wsgi.py' cannot be loaded as Python module., referer: http://localhost/
[Sat Apr 25 14:35:34.041279 2015] [:error] [pid 18599:tid 140003960342272] [client 127.0.0.1:51134] mod_wsgi (pid=18599): Exception occurred processing WSGI script '/var/www/html/koorimeo/koorimeo/wsgi.py'., referer: http://localhost/

According these message I found that apache2 can not find this module:

/var/www/html/koorimeo/wsgi.py

So I copy this path and try to get me clear wheather this file do exist:

bing@k-lab:/var/log/apache2$ ls /var/www/html/koorimeo/koorimeo/wsgi.py -l

and the system returned this message which told me that the file is truly exists...

-rw-rw-r-- 1 bing bing 389  4月 25 14:21 /var/www/html/koorimeo/koorimeo/wsgi.py

And I also make sure that I've installed libapache2-mod-wsgi-py3, I did find wsgi.so in proper location.

I've found wsgi.load in modes-enable and pointed the wsgi.so in right place:

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

So... I am confused...

Please tell me why can't apache2 find this wsgi.py file?

7
  • 1
    No, the error doesn't say it can't find it; it says it had problems loading the file. That's probably because of dependencies; have you installed Django? And why aren't you using a virtualenv? Apr 25, 2015 at 9:50
  • I am new to django and i even do not know what virtualenv is....
    – Bing
    Apr 25, 2015 at 9:58
  • I can sure I've installed Django with source code.. I downloaded the tar.gz package, then extract and use the command "sudo python setup.py install" to finished the installation process
    – Bing
    Apr 25, 2015 at 10:01
  • I just know python2 is the default environment of linux system. But how to solve this dependencies problem? may I add and head of "/usr/bin/env python3"?
    – Bing
    Apr 25, 2015 at 10:16
  • Are you using a virtualenv ? This would make things easier for you, specially when dealing with multiple versions of python
    – Paco
    Apr 25, 2015 at 11:02

1 Answer 1

2

Remove mod_python from Apache if you are not using it.

Your mod_wsgi module was compiled for Python 3.4.0, but mod_python was compiled for 2.7.6. Because mod_python is using a different version it is overriding what Python version is used and this will stop mod_wsgi from working.

Read the many sections in the documentation starting at:

1
  • Thank you! With out your tip, I will never notice this log message... and How careless I am that even never keep an eye on that information...
    – Bing
    Apr 25, 2015 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.