Configuring mod_wsgi with Apache

826 views
Skip to first unread message

Roger Wayne

unread,
Sep 4, 2016, 1:16:01 AM9/4/16
to modwsgi
Hey everyone,

It seems you have stumbled upon this thread. If so and you know a good deal about running Python based applications through the help of mod_wsgi (and maybe Django) then it would be greatly appreciated if one of you could help me out of this bind.

You see, I am just trying to install mod_wsgi because it is way more efficient than just using traditional CGI. I am using an Apache (2.4) server via XAMPP. I should also mention I have Windows 7 and not Mac OS X or any distribution of Linux. I followed the official tutorial from the guy who made mod_wsgi, Graham Dumpleton, and I came into some erros. I went to stackoverflow and that helped me a little but didn't get me too much further.

I am almost positive I have all the necessary components but nothing seems to work. I am at the point where I am trying to run the makefile that builds the mod_wsgi.so and the error that I get is "module machine type 'x86' conflicts with target machine type 'x64' ". I assume some files are trying to build for an x86 platform while others are trying to build for an x64 I guess. I just am at a lost and don't know what to change so again, any help would definitely be appreciated!

Thanks in advance

Graham Dumpleton

unread,
Sep 4, 2016, 3:40:03 AM9/4/16
to mod...@googlegroups.com
You don’t want be trying to build mod_wsgi yourself from source code.

Have you tried to use binaries for mod_wsgi provided at:


Graham
Message has been deleted

Roger Wayne

unread,
Sep 4, 2016, 4:31:13 PM9/4/16
to modwsgi
I have. What I do is put the pre-compiled mod_wsgi.so file in the modules folder. Then I edit the hhtpd.conf file with the LoadModule line and the lines that add it to the directory, and XAMPP complains about how apache can not start for whatever reason. I tried multiple mod_wsgi.so files I found (even the one on the main github page). While I have not tried them all because I know there is a lot, I feel like maybe the problem isn't with files themselves. I am not sure what is going on, but if you or anyone could lead me in the right direction, that would be very much appreciated. 


By the way, this platform (Google Groups) is very confusing to work with for me. Forgive me if I spam you with replies.

Graham Dumpleton

unread,
Sep 4, 2016, 8:11:28 PM9/4/16
to mod...@googlegroups.com

On 5 Sep 2016, at 6:31 AM, Roger Wayne <perve...@gmail.com> wrote:

I have. What I do is put the pre-compiled mod_wsgi.so file in the modules folder. Then I edit the hhtpd.conf file with the LoadModule line and the lines that add it to the directory, and XAMPP complains about how apache can not start for whatever reason. I tried multiple mod_wsgi.so files I found (even the one on the main github page). While I have not tried them all because I know there is a lot, I feel like maybe the problem isn't with files themselves. I am not sure what is going on, but if you or anyone could lead me in the right direction, that would be very much appreciated. 

How did you extract the mod_wsgi.so file from the .whl files from:


It is not the .so file itself, but a zip file that needs to be unpacked.

Which of those files provided there did you use? What was the name?

Those binaries are also compiled for Apache form the Apache Lounge site. If you use a different Apache binary distribution it may not work.

It is important that you know whether your Apache is 32 bit or 64 bit. The Python version you have must be same architecture, ie., 32 bit or 64 bit, you cannot mix.

What architecture are you using, 32 bit or 64 bit and are you certain both Apache and Python are for that?

What version of Python are you using? Do you have more than one Python version installed?

What was the actual error message in the Apache error logs you get when it fails to start up?

Graham


Roger Wayne

unread,
Sep 5, 2016, 3:05:28 AM9/5/16
to modwsgi
How did you extract the mod_wsgi.so file from the .whl files from:

I used the pip tool and it gave an error saying "Could not find a version that satisfies
the requirement mod_wsgi (from version: ) No matching distribution found for mod_wsgi"

It is not the .so file itself, but a zip file that needs to be unpacked.

Which of those files provided there did you use? What was the name?

So I downloaded the zipped file and unpacked it. Form other sources, there are already complied mod_wsgi.so files but not in this folder so I figured I I had to compile and build it through the use of the makefiles in the win32 folder. So I modified the common-VC10.mk file and used the ap24-py34-VC10.mk file and ran into some trouble as stated before.

Those binaries are also compiled for Apache form the Apache Lounge site. If you use a different Apache binary distribution it may not work.

It is important that you know whether your Apache is 32 bit or 64 bit. The Python version you have must be same architecture, ie., 32 bit or 64 bit, you cannot mix.

What architecture are you using, 32 bit or 64 bit and are you certain both Apache and Python are for that?

What version of Python are you using? Do you have more than one Python version installed?

Both my Apache and Python are 32-bit. I do have two version of Python, Python 3.5 and 3.4. I tried it with 3.5 at first but I download 3.4 thinking it would work somehow. 

What was the actual error message in the Apache error logs you get when it fails to start up?

A good bit of it was "server certificate does NOT include an ID which matches the server name", but later on when I tried other stuff, it was telling me my one of my python scripts had a syntax error. Which is weird because it definitely did not and I ran it through the compiler to make sure. I attached the error log if you want to check it out. It is quite lengthy though as I did try many times.

I know there is definitely easier ways to doing all this but I am quite new to server-side Python scripting and just web development in general so if you can bear with me, that would be awesome.

Thanks
error.log

Graham Dumpleton

unread,
Sep 5, 2016, 6:00:26 AM9/5/16
to mod...@googlegroups.com
On 5 Sep 2016, at 5:05 PM, Roger Wayne <perve...@gmail.com> wrote:

How did you extract the mod_wsgi.so file from the .whl files from:

I used the pip tool and it gave an error saying "Could not find a version that satisfies
the requirement mod_wsgi (from version: ) No matching distribution found for mod_wsgi”

What was the exact pip command you used? Want to know whether you used the URL location from the Internet, or copied the file to local disk and tried to install it from there. Provide the actual command can so see.

It is not the .so file itself, but a zip file that needs to be unpacked.

Which of those files provided there did you use? What was the name?

So I downloaded the zipped file and unpacked it. Form other sources, there are already complied mod_wsgi.so files but not in this folder so I figured I I had to compile and build it through the use of the makefiles in the win32 folder. So I modified the common-VC10.mk file and used the ap24-py34-VC10.mk file and ran into some trouble as stated before.

The .whl file is a zip file is what I meant. So download from pythonlibs site and change extension from .whl to .zip if necessary and then unpack it.

You really want to avoid trying to compile it yourself as getting the right compiler is a pain. For Python 3.5 there are no instructions for how to get the corresponding compiler. They use different compiler to what 3.4 and before used.


Those binaries are also compiled for Apache form the Apache Lounge site. If you use a different Apache binary distribution it may not work.

It is important that you know whether your Apache is 32 bit or 64 bit. The Python version you have must be same architecture, ie., 32 bit or 64 bit, you cannot mix.

What architecture are you using, 32 bit or 64 bit and are you certain both Apache and Python are for that?

What version of Python are you using? Do you have more than one Python version installed?

Both my Apache and Python are 32-bit. I do have two version of Python, Python 3.5 and 3.4. I tried it with 3.5 at first but I download 3.4 thinking it would work somehow. 

But what mod_wsgi binaries were you using? That is why I think I already asked which you downloaded. That is, what was the actual name of package pulled down. They have architecture and version information in names. You have to use the correct one.

Am really surprised you would be using 32 bit. You would generally want to be using 64 bit these days.


What was the actual error message in the Apache error logs you get when it fails to start up?

A good bit of it was "server certificate does NOT include an ID which matches the server name", but later on when I tried other stuff, it was telling me my one of my python scripts had a syntax error. Which is weird because it definitely did not and I ran it through the compiler to make sure. I attached the error log if you want to check it out. It is quite lengthy though as I did try many times.

The errors in log are because you are trying to run stuff as CGI scripts and also because you are using Python 2 code and not Python 3 code. The way that ‘print()’ is used differs.

I know there is definitely easier ways to doing all this but I am quite new to server-side Python scripting and just web development in general so if you can bear with me, that would be awesome.

Thanks

--
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.
<error.log>

Roger Wayne

unread,
Sep 5, 2016, 2:56:32 PM9/5/16
to modwsgi
What was the exact pip command you used? Want to know whether you used the URL location from the Internet, or copied the file to local disk and tried to install it from there. Provide the actual command can so see.

"pip install mod_wsgi" I downloaded it to my hard drive and tried to install it from there.


The .whl file is a zip file is what I meant. So download from pythonlibs site and change extension from .whl to .zip if necessary and then unpack it.
You really want to avoid trying to compile it yourself as getting the right compiler is a pain. For Python 3.5 there are no instructions for how to get the corresponding compiler. They use different compiler to what 3.4 and before used.

But what mod_wsgi binaries were you using? That is why I think I already asked which you downloaded. That is, what was the actual name of package pulled down. They have architecture and version information in names. You have to use the correct one.

"mod_wsgi-4.4.23+ap24vc10-cp34-cp34m-win32.whl" but I also tried "mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win32.whl" on Python 3.5 . Also I went to the main github page and downloaded the zipped file mod_wsgi-4.5.5 I believe.

Am really surprised you would be using 32 bit. You would generally want to be using 64 bit these days.

Xampp was only available in 32-bit (for Windows) and as you stated before, everything has to be 32 or 64 bit. I tried out Wamp (it is available in 64-bit) but Xampp was more user friendly to me. Do you really think it is a good idea to be using 64 bit? I would say performance-wise, it would make a great deal of a difference but I don't know how much that difference would be.

The errors in log are because you are trying to run stuff as CGI scripts and also because you are using Python 2 code and not Python 3 code. The way that ‘print()’ is used differs.

This is where I am confused. My code in the CGI scrips is Python 3 code. I ran it through the compiler for Python, and I only have version 3. I was definitely lost when i saw that error because my compiler was saying that my code was good to go yet the error log said I had a syntax error. But now that you brought it up, Python 2 uses print without parenthesis. It still is strange because everything I have gotten so far were versions for Python 3, so Python 2 shouldn't even be a factor. At least I don't think. I attached the code that it was complaining about in case you wanted to check it out for yourself. But you are saying the extension should be .py instead of .cgi, , right? I thought it did not matter what the extension was but having the .py extension would make sense.


Thanks for sticking with me so far.
tasteful.cgi

Graham Dumpleton

unread,
Sep 6, 2016, 12:00:56 AM9/6/16
to mod...@googlegroups.com
On 6 Sep 2016, at 4:56 AM, Roger Wayne <perve...@gmail.com> wrote:

What was the exact pip command you used? Want to know whether you used the URL location from the Internet, or copied the file to local disk and tried to install it from there. Provide the actual command can so see.

"pip install mod_wsgi" I downloaded it to my hard drive and tried to install it from there.


Running ‘pip install mod_wsgi’ will always try and install mod_wsgi from source code downloaded from PyPi. This installation method is not supported on Windows.

Even if you installed the .whl file the correct way using pip, it installs it off in some directory in the Python installation. You would have to have found where it was installed and copied it into the Apache modules directory, or Use the full path to where it was installed in the LoadModule line.

How to do that is not documented at all by the person who makes those .whl files available. I am surprised anyone can work out what to even do with them.

The .whl file is a zip file is what I meant. So download from pythonlibs site and change extension from .whl to .zip if necessary and then unpack it.

You really want to avoid trying to compile it yourself as getting the right compiler is a pain. For Python 3.5 there are no instructions for how to get the corresponding compiler. They use different compiler to what 3.4 and before used.

But what mod_wsgi binaries were you using? That is why I think I already asked which you downloaded. That is, what was the actual name of package pulled down. They have architecture and version information in names. You have to use the correct one.

"mod_wsgi-4.4.23+ap24vc10-cp34-cp34m-win32.whl" but I also tried "mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win32.whl" on Python 3.5 . Also I went to the main github page and downloaded the zipped file mod_wsgi-4.5.5 I believe.


What is on the GitHub page is of no use really again as you likely want to avoid compiling from source code.

What you should have done is take the .whl file for whatever Python version you want to use, and change the .whl extension to .zip. Then use a zip unarchiver to extract the .so file out of it and copy it into your Apache modules directory. Did you do that?

Am really surprised you would be using 32 bit. You would generally want to be using 64 bit these days.

Xampp was only available in 32-bit (for Windows) and as you stated before, everything has to be 32 or 64 bit. I tried out Wamp (it is available in 64-bit) but Xampp was more user friendly to me. Do you really think it is a good idea to be using 64 bit? I would say performance-wise, it would make a great deal of a difference but I don't know how much that difference would be.

The errors in log are because you are trying to run stuff as CGI scripts and also because you are using Python 2 code and not Python 3 code. The way that ‘print()’ is used differs.

This is where I am confused. My code in the CGI scrips is Python 3 code. I ran it through the compiler for Python, and I only have version 3. I was definitely lost when i saw that error because my compiler was saying that my code was good to go yet the error log said I had a syntax error. But now that you brought it up, Python 2 uses print without parenthesis. It still is strange because everything I have gotten so far were versions for Python 3, so Python 2 shouldn't even be a factor. At least I don't think. I attached the code that it was complaining about in case you wanted to check it out for yourself. But you are saying the extension should be .py instead of .cgi, , right? I thought it did not matter what the extension was but having the .py extension would make sense.


Thanks for sticking with me so far.

--
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.
<tasteful.cgi>

Roger Wayne

unread,
Sep 6, 2016, 9:17:46 PM9/6/16
to modwsgi
So I tried multiple times to put mod_wsgi.so files in the moduels folder then proceed to add the lines
"LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /<yourfoldername>"C:/xampp/htdocs/<yourfoldername>/"
<Directory "C:/xampp/htdocs/<yourfoldername>">
    Order allow,deny
    Allow from all
</Directory>"
Where <yourfoldername> would be my folder name. It always crashes. Now I noticed I can do the
LoadModule wsgi_module moduels/mod_wsgi.so line and it works fine but when i put the rest, it crashes. Weird thing is that it does not even write anything into the error log file. Maybe the syntax for the lines below or wrong but I am just following what other people have done and said has worked.

Graham Dumpleton

unread,
Sep 6, 2016, 9:22:21 PM9/6/16
to mod...@googlegroups.com
At this point I am going to say it may well be a mismatch with that Apache distribution. You really need to be using the same Apache distribution as it was compiled for. Especially when the Apache version compiled against is quite different to what you are running, especially where was is running is older, then wouldn’t be surprised it might crash.

Can you try the same Apache distribution as was used when mod_wsgi was compiled, as indicated on whatever site you downloaded the binary from.

Roger Wayne

unread,
Sep 6, 2016, 9:41:48 PM9/6/16
to modwsgi
I tried that after again after I saw your last reply.I go the .so file from mod_wsgi-4.4.23+ap24vc10-cp34-cp34m-win32.whl and it did not work. I tried it with mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win32.whl as well. Both seem to not work. Is there some prerequisite that I have to have besides just having the matching version of Apache and Python?

Graham Dumpleton

unread,
Sep 6, 2016, 9:46:08 PM9/6/16
to mod...@googlegroups.com

> On 7 Sep 2016, at 11:41 AM, Roger Wayne <perve...@gmail.com> wrote:
>
> I tried that after again after I saw your last reply.I go the .so file from mod_wsgi-4.4.23+ap24vc10-cp34-cp34m-win32.whl and it did not work. I tried it with mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win32.whl as well. Both seem to not work. Is there some prerequisite that I have to have besides just having the matching version of Apache and Python?

Python must be installed for all users, and not just yourself. It is an option of the GUI based installer. If you use the batch script installer it is harder as think you have to actually supply some option or change a config file.

Architecture of 32 bit vs 64 bit.

Preferably the same Apache distribution as mod_wsgi was compiled for and not an Apache distribution with version older than what mod_wsgi was compiled for. This is why I asked you to ensure you are using the same Apache distribution

Not sure if necessary now, but with older Python versions you also had to ensure you had the C runtime libraries for the version of the compiler being used if you hadn’t installed that specific compiler.

Graham

Roger Wayne

unread,
Sep 6, 2016, 9:52:01 PM9/6/16
to modwsgi
I see. Well I have two versions of Python. One is only installed for the root account, and the other for all users. This may or may not have something to do with it, but the one in PATH is the one only the root user has access to.

As for the last thing you mentioned, I would not be sure how to check that unfortunately. but I believe I installed most if not all the packages for both versions of Python.

Graham Dumpleton

unread,
Sep 6, 2016, 9:55:21 PM9/6/16
to mod...@googlegroups.com

> On 7 Sep 2016, at 11:52 AM, Roger Wayne <perve...@gmail.com> wrote:
>
> I see. Well I have two versions of Python. One is only installed for the root account, and the other for all users. This may or may not have something to do with it, but the one in PATH is the one only the root user has access to.
>
> As for the last thing you mentioned, I would not be sure how to check that unfortunately. but I believe I installed most if not all the packages for both versions of Python.

Have you ever considering investigating Docker?

The Windows platform is not a good platform for software development when using Python.

If you ran Docker, then you could use Linux inside of a container and use tools which are known to work better.

Graham

Roger Wayne

unread,
Sep 6, 2016, 10:02:45 PM9/6/16
to modwsgi
Basically it is like the Wine for Linux? I heard of it but if it would make things easier, I think it would definitely save me trouble. If I do pursue this, do you think  putting the mod_wsgi.so file in the folder and editing the httpd.conf file like I was trying to do would work without any problems?

Graham Dumpleton

unread,
Sep 6, 2016, 10:10:11 PM9/6/16
to mod...@googlegroups.com

> On 7 Sep 2016, at 12:02 PM, Roger Wayne <perve...@gmail.com> wrote:
>
> Basically it is like the Wine for Linux?

No, I wouldn’t use that analogy at all. It has got nothing to do with running Windows programs on Linux.

> I heard of it but if it would make things easier, I think it would definitely save me trouble. If I do pursue this, do you think putting the mod_wsgi.so file in the folder and editing the httpd.conf file like I was trying to do would work without any problems?

Many people have had no problems getting mod_wsgi to work on Windows. It is impossible to know how your environment is set up whether you do in fact have all the right bits, and it is very important to have the right bits when using Windows.

Using Linux is much much simpler as you either are using system supplied binaries which have been matched together for you already, or you compile from source code and get exactly what you need. The latter is much more straightforward on Linux. Using Docker presents even simpler ways of doing things as there are Docker base images out there that have everything set up for you and you just need to add in your application code.

Right now it is becoming too difficult to understand what state your Windows system is in. Thus why perhaps suggest spend a bit of time learning about Docker and also Linux in general.

the other option is to not try and do things on your own system, but use a hosting service where they worry about setting up the server software. For experimenting, Heroku has a hobby tier which doesn’t cost any money.

Graham

Roger Wayne

unread,
Sep 6, 2016, 10:20:53 PM9/6/16
to modwsgi
I see. So Docker can provide somewhat of a all-in-one package so I don't have to worry about configuring anything? Well either way, it seems that maybe would be a simpler solution. I will try to tinker with what I have a bit more to see if I can get it to work. I feel like I am close. If I do succeed, I will post it here so in case anyone runs into the same problem, they can check it out. If not then the solutions you provided would be the next best thing.

Thanks for all the help, Graham. 

Roger Wayne

unread,
Sep 7, 2016, 5:01:18 PM9/7/16
to modwsgi
Good gravy, I finally got it working! Well at least I can print out "Hello World!". 
So what worked for me is getting the corresponding .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi and changing the extenzion to .zip and unpacking it. Once that is done, fine the mod_wsgi.so and put it in the modules folder for Apache. Now here was the part that was tripping me up all this time. When editing the httpd.conf file, I tried doing what most others seem to have done and put in
"LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /<yourfoldername>"C:/xampp/htdocs/<yourfoldername>/"
<Directory "C:/xampp/htdocs/<yourfoldername>">
    Order allow,deny
    Allow from all
</Directory>"

My Apache would not even start up when I put that in there, but I noticed it would at least start up if I left the 
LoadModule line in there, so it was finding mod_wsgi.so fine. My next assumption was maybe the syntax was wrong for my Apache even though it seems to have worked for so many other people. What worked for me was
"LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /<folder_name> "C:/xampp/htdocs/<folder_name>/<file_name>.py/wsgi"
AddHandler wsgi-script .wsgi

<Directory "C:/xampp/htdocs/<folder_name>">
Order allow,deny
Allow from all
</Directory>"

The filename extension can be either .wsgi or .py but NOT .cgi, so be careful there. After that I was still running into trouble trying to get an example script running and the Apache error logs main fuss was about the variable that would contain my "Hello World!" was returning a str (sting) instead of a bit string. If you can not get that example script running, or any script really, because you get an error like then I suggest looking here.  After all that was done, I was able to print out "Hello World!" finally. I do still get some warnings in the error log saying something about certificate not matching but I assume it is not that big of a deal. I hope this helps anyone in the situation I was in.

Cheers

Graham Dumpleton

unread,
Sep 7, 2016, 6:11:37 PM9/7/16
to mod...@googlegroups.com
On 8 Sep 2016, at 7:01 AM, Roger Wayne <perve...@gmail.com> wrote:

Good gravy, I finally got it working! Well at least I can print out "Hello World!". 
So what worked for me is getting the corresponding .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi and changing the extenzion to .zip and unpacking it. Once that is done, fine the mod_wsgi.so and put it in the modules folder for Apache. Now here was the part that was tripping me up all this time. When editing the httpd.conf file, I tried doing what most others seem to have done and put in
"LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /<yourfoldername>"C:/xampp/htdocs/<yourfoldername>/"
<Directory "C:/xampp/htdocs/<yourfoldername>">
    Order allow,deny
    Allow from all
</Directory>"

My Apache would not even start up when I put that in there, but I noticed it would at least start up if I left the 
LoadModule line in there, so it was finding mod_wsgi.so fine. My next assumption was maybe the syntax was wrong for my Apache even though it seems to have worked for so many other people. What worked for me was
"LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /<folder_name> "C:/xampp/htdocs/<folder_name>/<file_name>.py/wsgi"
AddHandler wsgi-script .wsgi

You should not even need this AddHandler line.

The WSGIScriptAlias also looks a bit bogus still and how you have it will cause issues later if the WSGI application needs to know where it is mounted.

Generally you would if want WSGI application to appear at the root of the site use just:

    WSGIScriptAlias / "C:/xampp/htdocs/<folder_name>/<file_name>.py”

This would be accessed as:


Alternately if you did want it access at a sub URL, you would use:

   WSGIScriptAlias /suburl "C:/xampp/htdocs/<folder_name>/<file_name>.py”

and access it as:


Graham

<Directory "C:/xampp/htdocs/<folder_name>">
Order allow,deny
Allow from all
</Directory>"

The filename extension can be either .wsgi or .py but NOT .cgi, so be careful there. After that I was still running into trouble trying to get an example script running and the Apache error logs main fuss was about the variable that would contain my "Hello World!" was returning a str (sting) instead of a bit string. If you can not get that example script running, or any script really, because you get an error like then I suggest looking here.  After all that was done, I was able to print out "Hello World!" finally. I do still get some warnings in the error log saying something about certificate not matching but I assume it is not that big of a deal. I hope this helps anyone in the situation I was in.

Cheers

Roger Wayne

unread,
Sep 7, 2016, 6:29:03 PM9/7/16
to modwsgi
I tried it out and you are right. The AddHandler line is not needed. And I did not know it could be done that way. I am unfamiliar with this syntax so i just follow what everyone else did. But thanks for that bit of information. I'm trying to learn all this one step at a time, but I am making progress thankfully.

Roger Wayne

unread,
Sep 23, 2016, 3:28:37 PM9/23/16
to modwsgi
I have returned. It seemed like all was working well when I ran into trouble trying to parse HTML data from my Python script. I just assumed it was maybe my script or my front-end code that was the problem. In my Python script, I set the running instance of it on port 8080 and when I tried to connect there via my web browser, it could not connect. So somehow it is not starting up in the first place. I assume this maybe has something to do with the configuration of mod_wsgi, but I could be wrong.

The part that starts my WSGI application is:

if __name__ == '__main__':
    try:
        from wsgiref.simple_server import make_server
        httpd = make_server('localhost', 8080, app)
        print('Serving on port 8080...')
        httpd.serve_forever()
    except KeyboardInterrupt:
        print('Goodbye.')

And what I used to load mod_wsgi and my application into the Apache server is:

LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /wsgi "C:/xampp/htdocs/wsgi/app.py"

<Directory "C:/xampp/htdocs/wsgi">
Order allow,deny
Allow from all
</Directory>

I thought all was well but I'm going wrong somewhere I guess. Any help would be appreciated.

Graham Dumpleton

unread,
Sep 23, 2016, 6:40:00 PM9/23/16
to mod...@googlegroups.com
The snippet you provided is not a WSGI application, it is the startup code for a standalone web application which you would run from the command line. That could would not be executed under Apache/mod_wsgi.

You can see an example of a WSGI application in the documentation at:


Importantly, the WSGI application entry point needs to be called ‘application’ and not ‘app’ as your snippet was using.

You would connect with the URL ‘http://localhost' from your browser if Apache is running on your own machine. No port number is required as Apache would be listening on the standard port.

Once you get that hello world application running, I would very much suggest you go look at using a WSGI framework such as Flask as it will set you down the right path, ensuring you don’t try and do everything form scratch, which with WSGI is hard and a large waste of time when all you want to do is write a web application. You can find Flask at:


Make sure you get that simple WSGI hello world working first though so you verify your server setup works.

Graham

Roger Wayne

unread,
Sep 23, 2016, 7:31:36 PM9/23/16
to modwsgi
Thanks for the advice, Graham! But I am still a little bit confused though. If you set your application to run on port 8080, shouldn't there be something there when you try to connect to http:localhost:8080? Well at least able to connect to the application running there? I am able to print "Hello World" out jut fine in my main directory but when I try go to port 8080, I can not connect.

Graham Dumpleton

unread,
Sep 23, 2016, 7:40:34 PM9/23/16
to mod...@googlegroups.com

> On 24 Sep 2016, at 9:31 AM, Roger Wayne <perve...@gmail.com> wrote:
>
> Thanks for the advice, Graham! But I am still a little bit confused though. If you set your application to run on port 8080, shouldn't there be something there when you try to connect to http:localhost:8080? Well at least able to connect to the application running there? I am able to print "Hello World" out jut fine in my main directory but when I try go to port 8080, I can not connect.

The section in the __main__ is not run under mod_wsgi because your script is not being run like a main program on the command line. The code is loaded like a module. It is then Apache that is accepting requests, on port 80, processes the request and then hands it off to a WSGI application by calling the WSGI application entrypoint (function or other callable object) called ‘application’ in the WSGI script file.

So port 8080 never comes into the picture as it isn’t using the wsgiref web server to do anything.

Graham

Roger Wayne

unread,
Sep 23, 2016, 7:56:35 PM9/23/16
to mod...@googlegroups.com
Thank you. I would have never came to that conclusion. If that is the case, would you happen to know when referencing the program, what do I actually refer to? The program itself (the file) or where it is running on your localhost? I mean this in a way towards using POST requests with AJAX in a JavaScript.

Graham Dumpleton

unread,
Sep 23, 2016, 8:00:34 PM9/23/16
to mod...@googlegroups.com

On 24 Sep 2016, at 9:56 AM, Roger Wayne <perve...@gmail.com> wrote:

Thank you. I would have never came to that conclusion. If that is the case, would you happen to know when referencing the program, what do I actually refer to? The program itself (the file) or where it is running on your localhost? I mean this in a way towards using POST requests with AJAX in a JavaScript.

Don’t understand what you are asking. You will need to clarify what you are wanting to know.

You also might want to go read about how web servers work in general so you understand more about using them.


Not saying you should build your own web server, but if you don’t understand how they work and about addressing functionality of a web application using URLs, it may help.

Graham

Roger Wayne

unread,
Sep 23, 2016, 8:06:28 PM9/23/16
to mod...@googlegroups.com
I apologize. Maybe an example would help clarify. For CGI, when using POST/GET requests, you refer to the actual file itself.

xhttp.open("POST","filename.py",true);

Is it the same deal with a WSGI application?

And thanks for the additional resources. When I get the basics running, I will look into it.

Graham Dumpleton

unread,
Sep 23, 2016, 8:19:28 PM9/23/16
to mod...@googlegroups.com
How you make web requests depends on the client you are using. Go read those posts and you will leant more about how URLs work and how to address your web application. You will save your own time and ours by learning about it rather than fiddling around trying to make it work by trial and error.

Graham
--

Roger Wayne

unread,
Sep 23, 2016, 8:27:34 PM9/23/16
to mod...@googlegroups.com
Will do. Thanks for all the help again.
Reply all
Reply to author
Forward
0 new messages