0

I am learning django, and I am trying to deploy my first basic django under apache.

What I have done so far: under root:

installed python3.4
pip3.4 install virtualenvwrapper

under user "Cheng":

added to .bashrc:
    VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.4
    source /usr/local/bin/virtualenvwrapper.sh
mkvirtulenv ifthq

under root

pip3.4 install django

under "(ifthq)cheng"

navigate to /var/www
django-admin.py startproject ifthq
cd ifthq
python manage.py runserver  <--works no problem

Then the fun part, attaching the project to apache:

Under root, I set ifthq.conf in the conf.d directory of /etc/httpd/. inside ifthq.conf is:

WSGIPythonPath /var/www/ifthq:/home/cheng/.virtualenvs/ifthq/lib/python3.4/site-packages/

<VirtualHost *:80>
    ServerName www.ifthq.com
    ServerAlias ifthq.com
    ServerAdmin cheng@trekfederation.com

        <Directory />
         Options FollowSymLinks
         AllowOverride None
        </Directory>

         # Alias /robots.txt /www/STORE/coffestatic/robots.txt
         # Alias /favicon.ico /www/STORE/coffeestatic/favicon.ico

         Alias /static/ /var/www/ifthq/static/


        <Directory /var/www/ifthq/>
         Order allow,deny
         Allow from all
        </Directory>

    WSGIScriptAlias / /var/www/ifthq/ifthq/wsgi.py

    ErrorLog /var/log/httpd/error.log

    LogLevel warn

    CustomLog /var/log/httpd/access.log combined
</VirtualHost>

when I fire up apache, I get the notorious 500 (Internal Server Error). Upon further review, I get this response from error.log:

[Sun Oct 18 18:34:55.944407 2015] [:error] [pid 19250] [client 144.76.29.66:56465] ImportError: No module named django.core.wsgi

As you can see, I'm trying to get apache to serve the page. The wgsi.py location is correct. The site-packages location is correct. I feel like I'm missing something silly here. in root outside virtualenv, I did a pip3.4 install django to no avail.

What else am I missing? Thanks

UPDATE 1 here is my wsgi.py updated, still no go:

"""
WSGI config for ifthq 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, sys
# add the hellodjango project path into the sys.path
sys.path.append('/var/www/ifthq')

# add the virtualenv site-packages path to the sys.path
sys.path.append('/home/cheng/.virtualenvs/ifthq/lib/python3.4/site-packages')

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()
arcee123
  • 101
  • 9
  • 41
  • 118

2 Answers2

1

Have you tried this yet? ImportError: No module named django.core.wsgi Apache + VirtualEnv + AWS + WSGI I think it's a problem with your wsgi.py code.

EDIT:

I can show you the configuration that worked for me in a Centos VPS:

In httpd.conf

WSGIPythonPath /path/to/project/folder
<VirtualHost YourServerIp:80>
     #WSGI conf

     ServerName mysite.co
     ServerAlias www.mysite.co
     WSGIScriptAlias / /path/to/your/project/main/wsgi.py

     Alias /robots.txt /path/to/your/robots.txt/folder

     Alias /media/ /path/to/your/project/media/folder/
     Alias /static/ /path/to/your/project/static/folder/

     <Directory /path/to/your/project/static/folder/>
     Order deny,allow
     Allow from all
     </Directory>

     <Directory /path/to/your/project/media/folder/>
     Order deny,allow
     Allow from all
     </Directory>

     <Directory /path/to/your/project/wsgi.py/folder/>
     <Files wsgi.py>
     Order deny,allow
     Allow from all
     </Files>
     </Directory>
</VirtualHost>

And in my wsgi.py

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

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MainFolder.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Community
  • 1
  • 1
Jose Romero
  • 559
  • 2
  • 12
  • Jose, thanks much for response. I tried to add the requisite lines in wsgi.py, but I am still getting the same response. Any other ideas? – arcee123 Oct 19 '15 at 00:38
  • Have you already loaded mod_wsgi in Apache? With something like LoadModule wsgi_module modules/mod_wsgi.so in the httpd.conf file? – Jose Romero Oct 19 '15 at 02:29
  • yes. the command `httpd -D DUMP_MODULES` resulted in this line `wsgi_module (shared)` – arcee123 Oct 19 '15 at 02:31
0

i found the answer. Using another stackoverflow, which I'm trying to re-locate again....I found out that my mod_wsgi was setup under the default python when installed under YUM.

So this is what I did: I downloaded the new mod_wsgi from source, extracted it, then went into the folder. I then ran the following:

sudo ./configure --with-python=/usr/local/bin/python3.4
sudo make
sudo make install

This reset the mod_wsgi to the correct python, and from there, it all fell into place.

arcee123
  • 101
  • 9
  • 41
  • 118