Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the server configuration

4,345 views
Skip to first unread message

Chuck

unread,
May 12, 2011, 8:00:41 PM5/12/11
to modwsgi
I'm sorry if this is a pain to answer this question because it
probably is the "stock" newbie whine.

I'm getting the ubiquitous Invalid command 'WSGIScriptAlias', perhaps
misspelled or defined by a module not included in the server
configuration

when i try to boot up the Apache server.

I have already tried some of the recommendations in the installation
help files.

I'm willing to do what it takes to get this to work...

Some background info:

-- Django 1.2.5 (SUSE repo install)
-- Python 2.6 (SUSE repo install)
-- Server version: Apache/2.2.15 (Linux/SUSE)
-- mod_wsgi 3.3.17 (SUSE repo install) installed this in my /usr/lib64/
apache2/mod_wsgi.so

I tried to configure this according to the book Beginning Django E-
commerce. The author suggested you create a virtual host, which I
did. In SUSE you create a virtual host configuration file at/etc/
apache2/v.hosts.d. It's pointing to where my Django project is
located. Within my Django project I have an apache folder in which I
have placed a django.wsgi file. I've not changed anything in my
httpd.conf.

/usr/sbin/httpd2 -M

Loaded Modules:
core_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
actions_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_file_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_default_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cgi_module (shared)
dir_module (shared)
env_module (shared)
expires_module (shared)
include_module (shared)
log_config_module (shared)
mime_module (shared)
negotiation_module (shared)
setenvif_module (shared)
ssl_module (shared)
userdir_module (shared)

Questions:
1) should I have created mod_wsgi from source?
2) should I be fooling around with a virtual host?

I'm willing to provide any other information needed.

Graham Dumpleton

unread,
May 12, 2011, 8:25:34 PM5/12/11
to mod...@googlegroups.com
On 13 May 2011 10:00, Chuck <imter...@yahoo.com> wrote:
> I'm sorry if this is a pain to answer this question because it
> probably is the "stock" newbie whine.
>
> I'm getting the ubiquitous Invalid command 'WSGIScriptAlias', perhaps
> misspelled or defined by a module not included in the server
> configuration

Ubiquitous is probably not the right word as this doesn't come up often.

In short, it means that the line:

LoadModule wsgi_module modules/mod_wsgi.so

(where the path argument may be different for your installation), has
been added to Apache configuration, or if it is in a Apache
configuration file snippet file for the module, eg., wsgi.load, that
that module hasn't been enabled using the appropriate distributions
script for enabling Apache modules.

So, can you find a LoadModule line for wsgi_module anywhere in your
Apache configuration files?

Graham

> --
> You received this message because you are subscribed to the Google Groups "modwsgi" group.
> To post to this group, send email to mod...@googlegroups.com.
> To unsubscribe from this group, send email to modwsgi+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
>
>

Chuck

unread,
May 12, 2011, 8:25:59 PM5/12/11
to modwsgi
Doing some research in other posts...I have at least gotten further
along. I had to figure out a way to include the mod_wsgi module in
the Apache modules. So I did this:

Solution – enable mod_wsgi on SuSE linux

1. Edit the file /etc/sysconfig/apache2 as root:
1. search for APACHE_MODULES, you should find a line like
this
APACHE_MODULES="suexec access actions alias auth auth_dbm
autoindex cgi dir env expires include log_config mime negotiation
setenvif userdir ssl php4"
2. Add wsgi to the content in the list between the “
3. Save the changes and quit
2. run SuSEconfig to update the apache configuration files
3. run /etc/init.d/apache2 restart to restart the Apache server

Verify that the mod_wsgi module is installed correctly
wsgi_module (shared)
Syntax OK

When I restart Apache it's not giving me an error anymore. I'll post
more info as I go.

Graham Dumpleton

unread,
May 12, 2011, 8:27:56 PM5/12/11
to mod...@googlegroups.com
On 13 May 2011 10:25, Chuck <imter...@yahoo.com> wrote:
> Doing some research in other posts...I have at least gotten further
> along.  I had to figure out a way to include the mod_wsgi module in
> the Apache modules.  So I did this:
>
> Solution – enable mod_wsgi on SuSE linux
>
>   1. Edit the file /etc/sysconfig/apache2 as root:
>         1. search for APACHE_MODULES, you should find a line like
> this
>            APACHE_MODULES="suexec access actions alias auth auth_dbm
> autoindex cgi dir env expires include log_config mime negotiation
> setenvif userdir ssl php4"
>         2. Add wsgi to the content in the list between the “
>         3. Save the changes and quit
>   2. run SuSEconfig to update the apache configuration files
>   3. run /etc/init.d/apache2 restart to restart the Apache server

Thanks for that. I didn't know that SuSE was so weird when it came to
enabling of the modules.

Graham

Chuck

unread,
May 12, 2011, 8:40:51 PM5/12/11
to modwsgi
It looks like the mod_wsgi module is getting loaded. Now the problem
seems to exist in my django.wsgi script within my Django app. When
looking at the Apache error log I am seeing this:

Exception occurred processing WSGI script

ImportError: Could not import settings 'firstdjango.settings' (Is it
on sys.path? Does it have syntax errors?): No module named
firstdjango.settings


On May 12, 8:27 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:

Graham Dumpleton

unread,
May 12, 2011, 8:52:02 PM5/12/11
to mod...@googlegroups.com
Quickest answer is for me to say go watch:

http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations

In that presentation I step through sys.path issues as well as
permission issues.

Also ensure you have also read:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

taking note of what it says about sys.path.

Graham

Chuck

unread,
May 12, 2011, 9:06:12 PM5/12/11
to modwsgi
This is the content of my wsgi file in my Django project.

import os, sys

# path to directory of the .wsgi file ('apache/')
wsgi_dir = os.path.abspath(os.path.dirname(__file__))

# path to project root directory (parent of 'apache/')
project_dir = os.path.dirname(wsgi_dir)

# add project directory to system's PATH
sys.path.append(project_dir)

# add the settings.py file to your system's PATH
project_settings = os.path.join(project_dir,'settings')

# explicitly define the DJANGO_SETTINGS_MODULE
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

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

I only have one settings file,which is named settings.py.

Now it's giving me an error about not finding TemplateSyntaxError:
Caught ImportError while rendering: No module named firstdjango.books

I have a project under my main app called books. The project is
called firstdjango.

I'll look at your post about permissions.

On May 12, 8:52 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> Quickest answer is for me to say go watch:
>
>  http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_...
>
> In that presentation I step through sys.path issues as well as
> permission issues.
>
> Also ensure you have also read:
>
>  http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
>
> taking note of what it says about sys.path.
>
> Graham
>

Graham Dumpleton

unread,
May 12, 2011, 9:13:30 PM5/12/11
to mod...@googlegroups.com
On 13 May 2011 11:06, Chuck <imter...@yahoo.com> wrote:
> This is the content of my wsgi file in my Django project.
>
> import os, sys
>
> # path to directory of the .wsgi file ('apache/')
> wsgi_dir = os.path.abspath(os.path.dirname(__file__))

So the WSGI script file is in directory something like
.../parent/firstdjango/apache directory.

> # path to project root directory (parent of 'apache/')
> project_dir = os.path.dirname(wsgi_dir)

This give project_dir as '.../parent/firstdjango'.

> # add project directory to system's PATH
> sys.path.append(project_dir)

You are only adding '.../parent/firstdjango' to sys.path.

> # add the settings.py file to your system's PATH
> project_settings = os.path.join(project_dir,'settings')
>
> # explicitly define the DJANGO_SETTINGS_MODULE
> os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
>
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
> I only have one settings file,which is named settings.py.
>
> Now it's giving me an error about not finding TemplateSyntaxError:
> Caught ImportError while rendering: No module named firstdjango.books

Which fails, because '.../parent' is not in sys.path.

You would also need:

sys.path.append(os.dirname(project_dir))

else it can't find 'firstdjango' in sys.path when search for project
package root.

For additional reading on the sys.path mess that Django has got itself
into read:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

Graham

Chuck

unread,
May 12, 2011, 9:49:46 PM5/12/11
to modwsgi
Ok, I modified the django.wsgi and instead put in the root of my app.

Here are the contents of the file:

import os
import sys

sys.path.insert(0, '/home/charles/projects/python/firstdjango')

os.environ['DJANGO_SETTINGS_MODULE'] = 'firstdjango.settings'

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

This does not give me an error. It presents me with the Django
welcome page and tells me I haven't configured a database or anything
in my settings. Obviously I have configured all of this stuff. I'm
not sure whether I'm getting closer or farther away from success.


On May 12, 9:13 pm, Graham Dumpleton <graham.dumple...@gmail.com>

Graham Dumpleton

unread,
May 12, 2011, 9:55:26 PM5/12/11
to mod...@googlegroups.com
On 13 May 2011 11:49, Chuck <imter...@yahoo.com> wrote:
> Ok, I modified the django.wsgi and instead put in the root of my app.
>
> Here are the contents of the file:
>
> import os
> import sys
>
> sys.path.insert(0, '/home/charles/projects/python/firstdjango')
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'firstdjango.settings'
>
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
> This does not give me an error.  It presents me with the Django
> welcome page and tells me I haven't configured a database or anything
> in my settings.  Obviously I have configured all of this stuff. I'm
> not sure whether I'm getting closer or farther away from success.

Which on first review shouldn't work, unless under:

/home/charles/projects/python/firstdjango

you have another directory called 'firstdjango' which is the actual
Django site directory containing the 'settings.py' file.

This is because 'firstdjango.settings' in Django settings module
ultimately means that Python goes looking for a file called
'firstdjango/settings.py' underneath the directories which are listed
in sys.path.

Graham

Chuck

unread,
May 12, 2011, 10:15:42 PM5/12/11
to modwsgi
I feel pretty stupid here. I just want to construct this django.wsgi
file.

I have a project at /home/charles/projects/python/firstdjango

This is where my settings.py lives...this is also where I decided to
put the django.wsgi file.

I also have references to views in my urls.py that point to a books
and contact subfolder underneath firstdjango.

I'm obviously doing something wrong here and I can't figure it out.

If you could be so generous...what would I do here?


On May 12, 9:55 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> ...
>
> read more »

Graham Dumpleton

unread,
May 12, 2011, 10:39:22 PM5/12/11
to mod...@googlegroups.com
On 13 May 2011 12:15, Chuck <imter...@yahoo.com> wrote:
> I feel pretty stupid here.  I just want to construct this django.wsgi
> file.
>
> I have a project at /home/charles/projects/python/firstdjango
>
> This is where my settings.py lives...this is also where I decided to
> put the django.wsgi file.
>
> I also have references to views in my urls.py that point to a books
> and contact subfolder underneath firstdjango.
>
> I'm obviously doing something wrong here and I can't figure it out.
>
> If you could be so generous...what would I do here?

Use:

import os
import sys

sys.path.insert(0, '/home/charles/projects/python')
sys.path.insert(0, '/home/charles/projects/python/firstdjango')

os.environ['DJANGO_SETTINGS_MODULE'] = 'firstdjango.settings'

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

This what the example in:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

effectively says with just the paths different.

Chuck

unread,
May 12, 2011, 11:20:52 PM5/12/11
to modwsgi
I added that and now I just get the Django welcome screen. Now what's
really weird is that even when I don't have apache running and I just
use the Django development server, I get the same page. Now my
development server doesn't work. I'm totally screwed.

On May 12, 10:39 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> ...
>
> read more »

Graham Dumpleton

unread,
May 12, 2011, 11:58:17 PM5/12/11
to mod...@googlegroups.com
That I can't help with too much.

BTW, if you are using embedded mode of mod_wsgi and not daemon mode,
and you were doing a complete stop/start of Apache, that may explain
why stuff was working when WSGI script sys.path wasn't what expected.
That is, in embedded mode, if you change WSGI script, just the WSGI
script file is reloaded and not the whole process. Thus multiple
changes to sys.path will accumulate across the changes. Read:

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Reloading_In_Embedded_Mode

Recommend you use daemon mode if you aren't already.

http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide#Delegation_To_Daemon_Process

Of daemon mode the whole process is restarted automatically when WSGI
script file changed. Read the full document about on source code
reloading to get the whole story.

Graham

Chuck

unread,
May 13, 2011, 12:09:28 AM5/13/11
to modwsgi
It looks like I may have this working now. It appears that something
was being cached. So I deleted the settings.pyc and rebooted the
server and it seems to work with wsgi on apache. I guess it helps to
not give up ;)

Thanks for all of your help...

On May 12, 11:58 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> That I can't help with too much.
>
> BTW, if you are using embedded mode of mod_wsgi and not daemon mode,
> and you were doing a complete stop/start of Apache, that may explain
> why stuff was working when WSGI script sys.path wasn't what expected.
> That is, in embedded mode, if you change WSGI script, just the WSGI
> script file is reloaded and not the whole process. Thus multiple
> changes to sys.path will accumulate across the changes. Read:
>
> http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Reloading_I...
>
> Recommend you use daemon mode if you aren't already.
>
> http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide#Delegat...
>
> Of daemon mode the whole process is restarted automatically when WSGI
> script file changed. Read the full document about on source code
> reloading to get the whole story.
>
> Graham
>
> ...
>
> read more »

Chuck

unread,
May 13, 2011, 7:31:24 PM5/13/11
to modwsgi
> ...
>
> read more »

Graham Dumpleton

unread,
May 13, 2011, 7:33:39 PM5/13/11
to mod...@googlegroups.com
This reply came through with no additional content. Did you mean to
send something?

Graham

Chuck

unread,
May 13, 2011, 8:16:44 PM5/13/11
to modwsgi
Thanks again for your help. I sent a little donation to help support
your cause ;) I enjoy the Python/Django community much more than the
Ruby/Rails community. The people seem more willing to help and suffer
less from the disease of arrogance.

This will come in doubly handy because the web host I signed up with
is using mod_wsgi. I'd also be willing to supplement your existing
documentation to include specific instructions for SuSE installations
-- which is lacking in a lot of Django documentation and books. SuSE
still has quite a following in Europe.

On May 13, 7:33 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> This reply came through with no additional content. Did you mean to
> send something?
>
> Graham
>
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages