3

Updated Question

[Mon Jul 18 09:20:10.517873 2016] [:error] [pid 30316:tid 139756302964480] [remote 122.164.94.99:48261] Traceback (most recent call last):
[Mon Jul 18 09:20:10.518005 2016] [:error] [pid 30316:tid 139756302964480] [remote 122.164.94.99:48261]   File "/var/www/rent/Rent/wsgi.py", line 20, in <module>
[Mon Jul 18 09:20:10.518141 2016] [:error] [pid 30316:tid 139756302964480] [remote 122.164.94.99:48261]     from django.core.wsgi import get_wsgi_application
[Mon Jul 18 09:20:10.518236 2016] [:error] [pid 30316:tid 139756302964480] [remote 122.164.94.99:48261] ImportError: No module named django.core.wsgi

My virtualhost

<VirtualHost *:80>
    ServerName  ip_address
    ServerAdmin webmaster@localhost

    Alias /static/  /var/www/rent/static/

    Alias /media/  /var/www/rent/media/

    WSGIScriptAlias /   /var/www/rent/Rent/wsgi.py

    WSGIDaemonProcess   Rent  python-path=/var/www/rent:/root/.virtualenvs/rent/lib/python2.7/site-packages

    WSGIProcessGroup    Rent

    <Directory /var/www/rent/static>
        Options -Indexes
        Order deny,allow
        Allow from all
    </Directory>

    <Directory /var/www/rent/media>
        Options -Indexes
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel warn

    ErrorLog    ${APACHE_LOG_DIR}/error.log
    CustomLog   ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
10
  • How is it "not working as expected"? Can you include some logs and error messages in your question? Commented Jul 12, 2016 at 5:51
  • @GarrettHyde Whatever modules I have installed in virtualenv it is showing as module not found Commented Jul 12, 2016 at 6:08
  • @GarrettHyde Added the log Commented Jul 12, 2016 at 11:35
  • 2
    Did you read the exception message in the log and check the value of TEMPLATE_DIRS? If the value is such that you should not get the error you are getting, are you sure that the server is pointing your Django application to the right settings? If you temporarily add raise Exception("Let's see.") at the start of your settings.py and try accessing your site again, does the exception show up in the logs? Commented Jul 12, 2016 at 14:27
  • 1
    So it sounds like your question has been answered. If it's still not working, can you please update the question to cover your new symptoms? Commented Jul 14, 2016 at 22:42

1 Answer 1

14
+100
WSGIDaemonProcess   Rent  python-path=/var/www/rent:/root/.virtualenvs/rent/lib/python2.7/site-packages

This is the most likely cause of the problem. You have created a virtualenv inside the super user's home folder. But that folder is unlikely to be accessible to apache. A user's home folder is not accessible to any other user by default.

The web server and the WSGI process will be running as a non privileged user typically named nobody, httpd, apache or something similar. While you can fix this problem by changing the permissions on /root/ that's a big no no. It would be less dangerous if it was an ordinary user but still not a good idea to do this.

The best solution is to put the virtualenv in a location accessible by the unprivileged user. /usr/local/virtualenv is a good location.

Please note that moving /root/.virtualenvs/ to /usr/local/virtualenv you will have to recreate it as follows

 source /root/.virtualenvs/rent/bin/activate
 pip freeze > /tmp/requirements.txt
 cd /usr/local/
 virtualenv virtualenv
 source virtualenv/bin/activate
 pip install -r /tmp/requirements.txt

then edit the httpd.conf file to reflect the new path.

Sign up to request clarification or add additional context in comments.

4 Comments

Using python-path to set up a Python virtual environment with mod_wsgi daemon mode is not the recommended method. Use python-home instead as explained in modwsgi.readthedocs.io/en/develop/user-guides/…
thanks @GrahamDumpleton will look that up and update the answer
I was going crazy, I had the same problem and I checked the paths thousands of times, here the solution! ty
THANKYOU! I was following the digitalocean page, and had multiple virtual environments, one for a staging site and the other for production site. You can imagine the confusion when testing a Django upgrade. +1 from me, but should be +1000

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.