{"id":5773,"date":"2016-01-22T13:34:53","date_gmt":"2016-01-22T12:34:53","guid":{"rendered":"http:\/\/emilkirkegaard.dk\/en\/?p=5773"},"modified":"2016-01-22T13:34:53","modified_gmt":"2016-01-22T12:34:53","slug":"django-wsgi-apache-error-500","status":"publish","type":"post","link":"https:\/\/emilkirkegaard.dk\/en\/2016\/01\/django-wsgi-apache-error-500\/","title":{"rendered":"django, wsgi, apache: error 500"},"content":{"rendered":"<h1 class=\"western\">The problem<\/h1>\n<p>Apache gives an error 500 (internal server error) when trying to access website running django 1.9 using wsgi based on the tutorial given at <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04\">https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04<\/a>. Running the server using the developmental server (manage.py runserver) works fine.<\/p>\n<p>Looking in the apache error log reveals:<\/p>\n<pre class=\"western\">[stuff] mod_wsgi (pid=20304): Target WSGI script '\/django\/XY_django\/XY\/XY\/wsgi.py' cannot be loaded as Python module. \r\n[stuff] mod_wsgi (pid=20304): Exception occurred processing WSGI script '\/django\/XY_django\/XY\/XY\/wsgi.py'.<\/pre>\n<p>[python traceback]<\/p>\n<p>[stuff] ImportError: No module named &#8216;XY&#8217;<\/p>\n<p>[this error is repeated twice]<\/p>\n<p>Various resources mention the same or similar problems:<\/p>\n<ol>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/6454564\/target-wsgi-script-cannot-be-loaded-as-python-module\">http:\/\/stackoverflow.com\/questions\/6454564\/target-wsgi-script-cannot-be-loaded-as-python-module<\/a><\/li>\n<li>http:\/\/stackoverflow.com\/questions\/9462212\/import-error-no-module-named-django<\/li>\n<li>lots of others<\/li>\n<\/ol>\n<h1 class=\"western\">Things I tried<\/h1>\n<ol>\n<li>Wrong ownership of django dir and files.<\/li>\n<\/ol>\n<ul>\n<ul>\n<li>Was root, changed to www-data.<\/li>\n<li>No change.<\/li>\n<\/ul>\n<\/ul>\n<ol start=\"2\">\n<li>Wrong version of wsgi.<\/li>\n<\/ol>\n<ul>\n<ul>\n<li>Ran:<\/li>\n<li>\n<pre class=\"western\">sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi\r\nsudo apt-get install libapache2-mod-wsgi-py3<\/pre>\n<\/li>\n<\/ul>\n<\/ul>\n<ul>\n<ul>\n<li>No, used the correct version.<\/li>\n<\/ul>\n<\/ul>\n<ol start=\"3\">\n<li>Wrong code with the static block in apache config.<\/li>\n<\/ol>\n<ul>\n<ul>\n<li>No, error persists after commenting it out.<\/li>\n<\/ul>\n<\/ul>\n<ol start=\"4\">\n<li><a href=\"https:\/\/code.google.com\/p\/modwsgi\/wiki\/ConfigurationDirectives#WSGIDaemonProcess\">WSGIDaemonProcess<\/a> python-path is wrong.<\/li>\n<\/ol>\n<ul>\n<ul>\n<li>I noticed that the path given in the tutorial has two folders separated by :, not just one:<\/li>\n<li>\n<pre class=\"western\">WSGIDaemonProcess django python-path=\/home\/user\/myproject:\/home\/user\/myproject\/myprojectenv\/lib\/python2.7\/site-package\r\nWSGIDaemonProcess django python-path=\/django\/env\/lib\/python3.4\/site-packages<\/pre>\n<\/li>\n<li>Replaced with:<\/li>\n<li>\n<pre class=\"western\">WSGIDaemonProcess django python-path=\/django\/XY_django\/XY:\/django\/env\/lib\/python3.4\/site-packages<\/pre>\n<\/li>\n<li>Worked!<\/li>\n<\/ul>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The problem Apache gives an error 500 (internal server error) when trying to access website running django 1.9 using wsgi based on the tutorial given at https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04. Running the server using the developmental server (manage.py runserver) works fine. Looking in the apache error log reveals: [stuff] mod_wsgi (pid=20304): Target WSGI script &#8216;\/django\/XY_django\/XY\/XY\/wsgi.py&#8217; cannot be loaded [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2089],"tags":[2297,2296,2154,2298],"class_list":["post-5773","post","type-post","status-publish","format-standard","hentry","category-programming","tag-apache","tag-django","tag-python","tag-wsgi","entry"],"_links":{"self":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/comments?post=5773"}],"version-history":[{"count":1,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5773\/revisions"}],"predecessor-version":[{"id":5774,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5773\/revisions\/5774"}],"wp:attachment":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/media?parent=5773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/categories?post=5773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/tags?post=5773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}