Which Apache config to not do with mod_wsgi express

348 views
Skip to first unread message

Anupam Jain

unread,
Jul 1, 2017, 3:14:55 AM7/1/17
to modwsgi
First of all - thanks for mod_wsgi express!

This post says "As to the configuration of Apache, there actually wasn't any."

Is it ok to assume that I dont need to do any configuration on Apache at all (as in nothing in conf-enabled/available and sites-enabled/available)? (That sounds to be too good to be true so thought to check)

I have setup everything for mod_wsgi express and getting the error "ImportError: No module named '(projectname)'"

This is not the one caused by circular imports but something to do with setting the path somewhere I think (as I learnt from some SO posts) but not entirely clear about it

I did setup a django.conf in Apache's conf-enabled, so I am suspecting that may be conflicting with something.

Anupam Jain

unread,
Jul 1, 2017, 3:31:39 AM7/1/17
to modwsgi
Could go past that error by adding the following in wsgi.py (as mentioned here)

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))

But cant see the Django site yet. Getting a 404. Perhaps I need to do the Virtual Host config anyways

Graham Dumpleton

unread,
Jul 1, 2017, 3:32:07 AM7/1/17
to mod...@googlegroups.com
On 1 Jul 2017, at 4:17 PM, Anupam Jain <anupa...@gmail.com> wrote:

First of all - thanks for mod_wsgi express!

This post says "As to the configuration of Apache, there actually wasn't any."

Is it ok to assume that I dont need to do any configuration on Apache at all (as in nothing in conf-enabled/available and sites-enabled/available)? (That sounds to be too good to be true so thought to check)

Do not touch any system Apache configuration files under /etc/apache2, /etc/httpd or whatever directory it is that your operating systems puts the Apache configuration. When you use mod_wsgi-express it completely ignores them, does not modify them, nor use them in any way.


I have setup everything for mod_wsgi express and getting the error "ImportError: No module named '(projectname)'"

What command did you run and what arguments to mod_wsgi-express?

If you get an error with that exact message, then it indicates you copied some template for something from somewhere where you were expected to replace '(projectname)' with a different value for your project. Did you do that? Or is this not actually the error message you go.

When you run mod_wsgi-express the directory you run mod_wsgi-express in should be added to the Python module search path, so as long as any modules can be imported from that location you should be good. If that shouldn't be the base directory for imports of your projects, you can use --working-directory option to override it, or use the --python-path option to specify additional directories to search for modules.

So what is the directory layout for your project, which directory are you running mod_wsgi-express from and with what arguments.

This is not the one caused by circular imports but something to do with setting the path somewhere I think (as I learnt from some SO posts) but not entirely clear about it

I did setup a django.conf in Apache's conf-enabled, so I am suspecting that may be conflicting with something.

It shouldn't as it will be ignored.

If you are using Django, you should perhaps look at:


Also worthwhile reading:


Note that if you have inherited an old Django code base which hasn't been updated correctly so the settings module includes settings defined in newer Django versions, and you have restructured your application code so the settings module is now at a different directory level, and you are using the method of integrating mod_wsgi-express into Django itself, you may also have issues with the settings module not being found when being imported.

So also indicate what version of Django your project code was originally created using.

Graham

Graham Dumpleton

unread,
Jul 1, 2017, 3:34:22 AM7/1/17
to mod...@googlegroups.com
You shouldn't need to add anything related to sys.path in the wsgi.py file.

As mentioned in other email, send what command you are running and with what arguments.

Make sure you add the option --log-to-terminal so you can see the error log.

Also show what the initial output from running the command is, plus what URL you are then using to access the site. By default you should use http://localhost:8000.

Graham

Anupam Jain

unread,
Jul 1, 2017, 3:39:55 AM7/1/17
to modwsgi
Sorry, our earlier messages crossed each other  

(now writing replies to your questions)

Anupam Jain

unread,
Jul 1, 2017, 3:52:20 AM7/1/17
to modwsgi
Answers inline, thanks


On Saturday, July 1, 2017 at 1:02:07 PM UTC+5:30, Graham Dumpleton wrote:

On 1 Jul 2017, at 4:17 PM, Anupam Jain <anupa...@gmail.com> wrote:

First of all - thanks for mod_wsgi express!

This post says "As to the configuration of Apache, there actually wasn't any."

Is it ok to assume that I dont need to do any configuration on Apache at all (as in nothing in conf-enabled/available and sites-enabled/available)? (That sounds to be too good to be true so thought to check)

Do not touch any system Apache configuration files under /etc/apache2, /etc/httpd or whatever directory it is that your operating systems puts the Apache configuration. When you use mod_wsgi-express it completely ignores them, does not modify them, nor use them in any way.

Thats great to know 


I have setup everything for mod_wsgi express and getting the error "ImportError: No module named '(projectname)'"

What command did you run and what arguments to mod_wsgi-express?

I used: mod_wsgi-express start-server wsgi.py 

If you get an error with that exact message, then it indicates you copied some template for something from somewhere where you were expected to replace '(projectname)' with a different value for your project. Did you do that? Or is this not actually the error message you go.
 
Thats not the exact message. I meant that its searching for the high level directory with the Django project name (directory structure below)

When you run mod_wsgi-express the directory you run mod_wsgi-express in should be added to the Python module search path, so as long as any modules can be imported from that location you should be good. If that shouldn't be the base directory for imports of your projects, you can use --working-directory option to override it, or use the --python-path option to specify additional directories to search for modules.

So what is the directory layout for your project, which directory are you running mod_wsgi-express from and with what arguments.

directory is something like this

projectname
     - appname
         - views.py
         - other files
     - projectname 
          - wsgi.py

running mod_wsgi-express from  /home/username/projectname/projectname

This is not the one caused by circular imports but something to do with setting the path somewhere I think (as I learnt from some SO posts) but not entirely clear about it

I did setup a django.conf in Apache's conf-enabled, so I am suspecting that may be conflicting with something.

It shouldn't as it will be ignored.

If you are using Django, you should perhaps look at:


Also worthwhile reading:


Note that if you have inherited an old Django code base which hasn't been updated correctly so the settings module includes settings defined in newer Django versions, and you have restructured your application code so the settings module is now at a different directory level, and you are using the method of integrating mod_wsgi-express into Django itself, you may also have issues with the settings module not being found when being imported.

So also indicate what version of Django your project code was originally created using.

The project was created on Django 1.10.2 and I am now moving it from dev to prod (GCP, Debian). Installed the same Django version on prod as well. I'll read the above Django posts as well but yes, I did create a settings directory under projectname/projectname which includes different versions of settings for dev and prod. I have set the environment variable for settings in the virtualenv's activate script. Also, os.environ.setdefault() is changed accordingly in wsgi.py

Graham

Graham Dumpleton

unread,
Jul 1, 2017, 3:54:33 AM7/1/17
to mod...@googlegroups.com
On 1 Jul 2017, at 5:52 PM, Anupam Jain <anupa...@gmail.com> wrote:

Answers inline, thanks

On Saturday, July 1, 2017 at 1:02:07 PM UTC+5:30, Graham Dumpleton wrote:

On 1 Jul 2017, at 4:17 PM, Anupam Jain <anupa...@gmail.com> wrote:

First of all - thanks for mod_wsgi express!

This post says "As to the configuration of Apache, there actually wasn't any."

Is it ok to assume that I dont need to do any configuration on Apache at all (as in nothing in conf-enabled/available and sites-enabled/available)? (That sounds to be too good to be true so thought to check)

Do not touch any system Apache configuration files under /etc/apache2, /etc/httpd or whatever directory it is that your operating systems puts the Apache configuration. When you use mod_wsgi-express it completely ignores them, does not modify them, nor use them in any way.

Thats great to know 


I have setup everything for mod_wsgi express and getting the error "ImportError: No module named '(projectname)'"

What command did you run and what arguments to mod_wsgi-express?

I used: mod_wsgi-express start-server wsgi.py 

If you get an error with that exact message, then it indicates you copied some template for something from somewhere where you were expected to replace '(projectname)' with a different value for your project. Did you do that? Or is this not actually the error message you go.
 
Thats not the exact message. I meant that its searching for the high level directory with the Django project name (directory structure below)

When you run mod_wsgi-express the directory you run mod_wsgi-express in should be added to the Python module search path, so as long as any modules can be imported from that location you should be good. If that shouldn't be the base directory for imports of your projects, you can use --working-directory option to override it, or use the --python-path option to specify additional directories to search for modules.

So what is the directory layout for your project, which directory are you running mod_wsgi-express from and with what arguments.

directory is something like this

projectname
     - appname
         - views.py
         - other files
     - projectname 
          - wsgi.py

running mod_wsgi-express from  /home/username/projectname/projectname

Wrong directory to run it from, plus you need extra arguments.

Read those other blogs posts I have linked to about using it with Django.

Once you have tried what is talked about in those, if still have issues let me know.

Graham


This is not the one caused by circular imports but something to do with setting the path somewhere I think (as I learnt from some SO posts) but not entirely clear about it

I did setup a django.conf in Apache's conf-enabled, so I am suspecting that may be conflicting with something.

It shouldn't as it will be ignored.

If you are using Django, you should perhaps look at:


Also worthwhile reading:


Note that if you have inherited an old Django code base which hasn't been updated correctly so the settings module includes settings defined in newer Django versions, and you have restructured your application code so the settings module is now at a different directory level, and you are using the method of integrating mod_wsgi-express into Django itself, you may also have issues with the settings module not being found when being imported.

So also indicate what version of Django your project code was originally created using.

The project was created on Django 1.10.2 and I am now moving it from dev to prod (GCP, Debian). Installed the same Django version on prod as well. I'll read the above Django posts as well but yes, I did create a settings directory under projectname/projectname which includes different versions of settings for dev and prod. I have set the environment variable for settings in the virtualenv's activate script. Also, os.environ.setdefault() is changed accordingly in wsgi.py

Graham


-- 
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Anupam Jain

unread,
Jul 1, 2017, 3:55:26 AM7/1/17
to modwsgi
This is the output from the command:

Server URL         : http://localhost:8000/

Server Root        : /tmp/mod_wsgi-localhost:8000:1001

Server Conf        : /tmp/mod_wsgi-localhost:8000:1001/httpd.conf

Error Log File     : /tmp/mod_wsgi-localhost:8000:1001/error_log (warn)

Request Capacity   : 5 (1 process * 5 threads)

Request Timeout    : 60 (seconds)

Startup Timeout    : 15 (seconds)

Queue Backlog      : 100 (connections)

Queue Timeout      : 45 (seconds)

Server Capacity    : 20 (event/worker), 20 (prefork)

Server Backlog     : 500 (connections)

Locale Setting     : en_US.UTF-8


I am using localhost:8000 to access the site. Will turn on the logging option to see the logs on the console. I have been seeing them from /tmp/mod_wsgi-localhost:8000:1001/error_log so far. 

Anupam Jain

unread,
Jul 1, 2017, 5:03:34 AM7/1/17
to modwsgi
(using mysite instead of projectname on this thread now, to be consistent with the docs)

I think I have read all the relevant parts of the doc now and followed it accurately but still getting the following error:

ImportError: No module named 'wsgi'


Directory Structure:

mysite

     - myapp

         - views.py

         - other files

     - mysite 

          - wsgi.py

          - __init__.py

          settings

                 - __init__.py

                 - base.py

                 - production.py

                 - development.py 



Running the following command from: home/username/mysite/


mod_wsgi-express start-server wsgi.py --application-type module mysite.wsgi --log-to-terminal


wsgi.py:


import os

# import sys

from django.core.wsgi import get_wsgi_application


# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))

# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings.production")

application = get_wsgi_application()

Anupam Jain

unread,
Jul 1, 2017, 5:15:04 AM7/1/17
to mod...@googlegroups.com
Also want to mention the value of WSGI_APPLICATION set in the Django settings file :
WSGI_APPLICATION = 'zoomio.wsgi.application'

I never set it so guessing that it was set by default when the project was created.

--
You received this message because you are subscribed to a topic in the Google Groups "modwsgi" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/modwsgi/_nUEp1WiRH4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to modwsgi+unsubscribe@googlegroups.com.

To post to this group, send email to mod...@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.



--
"What is meditation?" (http://www.heartfulness.org/)

Anupam Jain

unread,
Jul 1, 2017, 5:15:43 AM7/1/17
to mod...@googlegroups.com
I meant WSGI_APPLICATION = 'mysite.wsgi.application'

Graham Dumpleton

unread,
Jul 1, 2017, 6:21:03 AM7/1/17
to mod...@googlegroups.com
I would need to see the full traceback along with the error message.

Also, if in the same directory you run the 'python' interpreter and go:

    import mysite.wsgi

what happens?

And, what do you have BASE_DIR set to in production.py?

Graham

Anupam Jain

unread,
Jul 1, 2017, 6:48:19 AM7/1/17
to mod...@googlegroups.com
Here's the full traceback:

[Sat Jul 01 08:48:59.384492 2017] [wsgi:error] [pid 15499:tid 139843043293056] mod_wsgi (pid=15499): Target WSGI script '/tmp/mod_wsgi-localhost:8000:1001/handler.wsgi' cannot be loaded as Python module.[Sat Jul 01 08:48:59.384622 2017] [wsgi:error] [pid 15499:tid 139843043293056] mod_wsgi (pid=15499): Exception occurred processing WSGI script '/tmp/mod_wsgi-localhost:8000:1001/handler.wsgi'.[Sat Jul 01 08:48:59.384677 2017] [wsgi:error] [pid 15499:tid 139843043293056] Traceback (most recent call last):[Sat Jul 01 08:48:59.384855 2017] [wsgi:error] [pid 15499:tid 139843043293056]   File "/tmp/mod_wsgi-localhost:8000:1001/handler.wsgi", line 94, in <module>[Sat Jul 01 08:48:59.384888 2017] [wsgi:error] [pid 15499:tid 139843043293056]     recorder_directory=recorder_directory)[Sat Jul 01 08:48:59.385446 2017] [wsgi:error] [pid 15499:tid 139843043293056]   File "/home/anupam/ENV/lib/python3.4/site-packages/mod_wsgi/server/__init__.py", line 1374, in __init__[Sat Jul 01 08:48:59.385483 2017] [wsgi:error] [pid 15499:tid 139843043293056]     __import__(entry_point)
[Sat Jul 01 08:48:59.385523 2017] [wsgi:error] [pid 15499:tid 139843043293056] ImportError: No module named 'wsgi'


import mysite.wsgi does not give any errors (when run from the shell invoked from the same dir)

In production.py:
   BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

thanks,
Anupam



Graham

To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+unsubscribe@googlegroups.com.

To post to this group, send email to mod...@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "modwsgi" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/modwsgi/_nUEp1WiRH4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to modwsgi+unsubscribe@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.



--

Anupam Jain

unread,
Jul 1, 2017, 8:00:28 AM7/1/17
to mod...@googlegroups.com
Got past that error. My bad. I had an unneccessary wsgi.py in the following command:


mod_wsgi-express start-server wsgi.py --application-type module mysite.wsgi --log-to-terminal

Removed it and the following doesnt give the same error:
mod_wsgi-express start-server --application-type module mysite.wsgi --log-to-terminal

I do get a 404 still on localhost:8000 but that may be due to another reason, so will perhaps start a separate thread if need help on that.

Thanks!

Anupam Jain

unread,
Jul 1, 2017, 8:35:09 AM7/1/17
to mod...@googlegroups.com
For others, the 404 was because the prod server's IP/domain-name was not added in ALLOWED_HOSTS setting in Django.

Adding the following in production.py helped:
ALLOWED_HOSTS.extend(['prod_ip_here',
                    ])
Reply all
Reply to author
Forward
0 new messages