Monday, January 27, 2014

Re: Problems Setting Up wsgi and Apache

Tim,

I actually tried a symbolic link from my user account /home/django/django_app to /var/www/mom/myapp and apache is now reading the files and I have moved beyond the Forbidden error.

However, I now get an internal server error (which is an improvement!!). Apache is reading the wsgi.py file, but barfs at importing django.core.wsgi. 

ImportError: No module named django.core.wsgi

I have this at the top of the apache conf file for the site - 
WSGIPythonPath /home/django/.virtualenvs/inventory_project/lib/python2.7/site-packages/

which is the correct path to the site packages directory. Perhaps another permissions problem? 

Thanks,

Mark


On Mon, Jan 27, 2014 at 9:11 AM, Timothy W. Cook <tim@mlhim.org> wrote:
Mark,
I don't know if this will help.  But I found (on CentOS) I had to add the 'apache' user to the django users group.  Not that it should matter, but it seemed to.  This seemed to be easier to add group rw permissions to the django app directory.

HTH,
Tim



On Mon, Jan 27, 2014 at 2:01 PM, Mark Phillips <mark@phillipsmarketing.biz> wrote:
Fred,

Thanks for your help. I made some progress so far.

1. I discovered that I fogot to add the port 7000 to Apache´s ports.conf.

2. The Apache error logs were in /var/log/apache2/error.log and not in /var/log/apache2/mom/error.log. APACHE_LOG_DIR was not set.

2. Once I found the error logs, I found this - 
 
[Sun Jan 26 06:25:04.325511 2014] [:warn] [pid 3472] mod_wsgi: Compiled for Python/2.7.5+.
[Sun Jan 26 06:25:04.325576 2014] [:warn] [pid 3472] mod_wsgi: Runtime using Python/2.7.6.

I tried removing mod-python as recommended by the django docs, but that did not help. So I removed the Debian package for python-wsgi and compiled python-wsgi myself. 

I am not at the point where I get Forbidden - You don have permission to access /mom/inventory on this server. This is progress!! ;) 

I guess the current problem is that I cannot run the django app from a user account (/home/django/). I added the user django to the group www-data, but I still get the forbidden message. I will try moving it to /var/www as you have it set up. 

Thanks again!

Mark

P.S. I got a good chuckle from your signature block - "Open Source: Without walls and fences, we need no Windows or Gates." A small nit, but I believe it should read ..., we need no Windows nor Gates... to be grammatically correct.


On Sun, Jan 26, 2014 at 7:43 PM, Fred Stluka <fred@bristle.com> wrote:
Mark,

I'm doing this fine with Django 1.4.2 and Python 2.7.3.

My wsgi.py file looks like:


import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()



My Apache config looks like:



# WSGI setup, for use by Django and other Python webapps
# See notes in:
#  - http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
#  - http://code.google.com/p/modwsgi/wiki/ConfigurationIssues
#  - https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi
# --Fred 11/22/2012
WSGIPythonHome /var/python27/virtualenvs/hhl
<Directory "/var/www/wsgi-bin">
    Order allow,deny
    Allow from all
</Directory>
WSGIDaemonProcess wsgi_apps processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup  wsgi_apps
WSGIScriptAlias   /mypythonapp "/var/www/wsgi-bin/mypythonapp.wsgi"
WSGISocketPrefix  run/wsgi

#
# hhlweb Django app
#
<Directory "/var/www/django/hhlweb/apache">

    Order deny,allow
    Allow from all
</Directory>
WSGIDaemonProcess hhlweb processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup  hhlweb
# Note: Support both aliases for backward compatibility with release 1.
WSGIScriptAlias /hhlweb /var/www/django/hhlweb/apache/django.wsgi
WSGIScriptAlias /       /var/www/django/hhlweb/apache/django.wsgi

# Map the Django STATIC_URL to the Django STATIC_ROOT
<Directory /var/www/django/hhlweb/collected_static>

    Order deny,allow
    Allow from all
</Directory>
Alias /static/ /var/www/django/hhlweb/collected_static/

# Map the Django MEDIA_URL to the Django MEDIA_ROOT
<Directory /var/www/django/hhlweb/media>

    Order deny,allow
    Allow from all
</Directory>
Alias /media/ /var/www/django/hhlweb/media/



Hope this helps!
--Fred
Fred Stluka -- mailto:fred@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 1/26/14 5:15 PM, Mark Phillips wrote:
I have my first django app running using runserver. I am now trying to get Apache to serve my site. I have read the django docs and quite a few other references on the Internet, but I cannot get Apache to do anything with my django site. And no error message.

I am running django 1.6 in a virtual environment with Python 2.7 on Debian Linux inside my LAN. 

Configuration file for apache
/etc/apache2/sites-enabled/mom.conf:
<VirtualHost *:7000>
    ServerName beagle
    ServerAlias beagle
    ServerAdmin mark@beagle
    
    DocumentRoot /var/www/mom

    WSGIScriptAlias /mom /home/django/django_projects/inventory/inventory_project/wsgi.py

    <Directory /home/django/django_projects/inventory/inventory_project>
        Order deny,allow
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/mom/error.log
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/mom/access.log combined
</VirtualHost>

/home/django/django_projects/inventory/inventory_project/wsgi.py
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "inventory_project.settings.dev")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

The project layout:
/home/django/django_projects/
└── inventory
    ├── fabfile2.py
    ├── fabfile.py
    ├── inventory
    │   ├── admin.py
    │   ├── admin.py~
    │   ├── admin.pyc
    │   ├── forms.py
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── migrations
    │   ├── models.py
    │   ├── models.py~
    │   ├── models.pyc
    │   ├── templates
    │   ├── templatetags
    │   ├── tests.py
    │   ├── urls.py
    │   ├── urls.py~
    │   ├── urls.pyc
    │   ├── views.py
    │   ├── views.py~
    │   └── views.pyc
    ├── inventory_project
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── media
    │   ├── settings
    │   ├── settings.py
    │   ├── settings.py~
    │   ├── settings.pyc
    │   ├── settings.py.old
    │   ├── static
    │   ├── urls.py
    │   ├── urls.py~
    │   ├── urls.pyc
    │   ├── wsgi.py
    │   └── wsgi.pyc
    ├── manage.py
    ├── mom
    ├── Notes.txt
    ├── README
    └── requirements.txt

/etc/apache2/mods-enabled/wsgi.conf
 WSGIPythonPath /home/django/django_projects/inventory:/home/django/.virtualenvs/inventory_project/lib/
python2.7/site-packages/

Any ideas on why I only get "Ooops cannot connect to beagle:7000/mom"?

Thanks,

Mark
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEqej2O1ZfrsbywQWW9XSK5iEkybkMd4B%2B9Rxdi0bQC_Zzc%2BNA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/52E5C7E1.4060802%40bristle.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEqej2M4dNV%2B-SXvx%3DpfNH9UJ7pJgc7b%2BENK8CVfncqffCbxRA%40mail.gmail.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc           +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B%3DOU3XdhWppHFaXpWL%2BxAoCxK6gJZUkB%3DvgKH4j-EKCqvKFLQ%40mail.gmail.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEqej2PNFZu10vHSUdc9v%3DmdwtBYgcucUrFYu6527mVLTkd7tw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment