Installation under Apache/mod_wsgi: "ImportError: No module named site"
I try to setting apache webserver for running askbot in my local machine but i get this error in /var/log/httpd/error_log:
[Mon Mar 12 16:21:24 2012] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Mon Mar 12 16:21:24 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Mar 12 16:21:24 2012] [notice] Digest: generating secret for digest authentication ...
[Mon Mar 12 16:21:24 2012] [notice] Digest: done
[Mon Mar 12 16:21:25 2012] [notice] Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0g DAV/2 mod_wsgi/3.3 Python/2.7.2 configured -- resuming normal operations
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
This is my configuration for apache
#NOTE: the directory paths used here may be adjusted
#the following two directories must be both readable and writable by apache
WSGISocketPrefix /var/run/wsgi
#WSGIPythonEggs /usr/lib/python2.7/site-packages/
#the following directory must be readable by apache
WSGIPythonHome /usr/lib/python2.7
#NOTE: all urs below will need to be adjusted if
#settings.FORUM_SCRIPT_ALIAS is anything other than empty string (e.g. = 'forum/')
#this allows "rooting" forum at http://example.com/forum, if you like
#replace with 127.0.0.1 with real IP address
<VirtualHost 127.0.0.1:80>
ServerAdmin you@example.com
DocumentRoot /home/relax/Temp/askmath/
ServerName example.come
#aliases to serve static media directly
#will probably need adjustment
Alias /static/ /home/relax/Temp/askmath/static/
Alias /upfiles/ /home/relax/Temp/askmath/askbot/upfiles/
<DirectoryMatch "/home/relax/Temp/askmath/askbot/skins/([^/]+)/media">
Order deny,allow
Allow from all
</DirectoryMatch>
<Directory "/home/relax/Temp/askmath/askbot/upfiles">
Order deny,allow
Allow from all
</Directory>
#must be a distinct name within your apache configuration
WSGIDaemonProcess askbot2
WSGIProcessGroup askbot2
WSGIScriptAlias / /home/relax/Temp/askmath/django.wsgi
#make all admin stuff except media go through secure connection
<LocationMatch "/admin(?!/media)">
RewriteEngine on
RewriteRule /admin(.*)$ https://example.com/admin$1 [L,R=301]
</LocationMatch>
CustomLog /home/relax/Temp/askmath/log/access_log common
ErrorLog /home/relax/Temp/askmath/log/error_log
LogLevel debug
</VirtualHost>
#again, replace the IP address
<VirtualHost 127.0.0.1:443>
ServerAdmin you@example.com
DocumentRoot /home/relax/Temp/askmath
ServerName example.com
<LocationMatch "^(?!/admin)">
RewriteEngine on
RewriteRule django.wsgi(.*)$ http://example.com$1 [L,R=301]
</LocationMatch>
SSLEngine on
#your SSL keys
SSLCertificateFile /etc/httpd/conf/server.crt
SSLCertificateKeyFile /etc/httpd/conf/server.key
Alias /admin/media/ /usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/contrib/admin/media
WSGIScriptAlias / /home/relax/Temp/askmath/django.wsgi
CustomLog /home/relax/Temp/askmath/log/access_log common
ErrorLog /home/relax/Temp/askmath/log/error_log
</VirtualHost>
Adding
import sys
sys.stderr.write('\n'.join(sys.path))
at the end of the django.wsgi and running "python2 django.wsgi" i get this paths
/home/relax/Temp ...
Comments
There isn't any problem with the apache config file (aside from assuring that every path exists and the effective user of apache server has access to them). I would check what the paths (the contents of
sys.path
) are inside the/home/relax/Temp/askmath/django.wsgi
I add a debugging statements into the wsgi script and run it with python. I list all paths in the main question. I hope this can be helpful to find a solution. I'm going crazy ;)
Looks ok. Where does this exception occur? Thats where I would look into the paths, from the information you gave it is not clear in which file the error is thrown. Usually, when the exception like the one you mentioned in the title happens there is a file name and the line number where that happened. Can you clarify?
I don't know :(! i simply copy the log. Anyway change WSGIPythonHome to /usr and adding <Directory "/home/relax/Temp/askmath/"> Order allow,deny Allow from all </Directory> after WSGIScriptAlias / /home/relax/Temp/askmath/django.wsgi resolve partially the problem ;). Now i can see the site on my browser but without static content (css, image, etc). Any suggestion? Thanks
Ok, much better for static files you need to run in the beginning
python manage.py collectstatic
from the project directory.