Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_cgi , mod_fastcgi, mod_scgi , mod_wsgi, mod_python, FLUP. I don't know how many more. what is mod_php equivalent?

Tags:

python

php

apache

I recently learnt Python. I liked it. I just wanted to use it for web development. This thought caused all the troubles. But I like these troubles :)

Coming from PHP world where there is only one way standardized. I expected the same and searched for python & apache.

Setting up Python on Windows/ Apache? says

Stay away from mod_python. One common misleading idea is that mod_python is like mod_php, but for python. That is not true.

So what is equivalent of mod_php in python?

I need little clarification on this one How Python web frameworks, WSGI and CGI fit together

CGI, FastCGI and SCGI are language agnostic. You can write CGI scripts in Perl, Python, C, bash, or even Assembly :). So, I guess mod_cgi , mod_fastcgi, mod_scgi are their corresponding apache modules. Right?

WSGI is some kind of optimized/improved inshort an efficient version specifically designed for python language only. In order to use this mod_wsgi is a way to go. right?

This leaves out mod_python. What is it then?

Apache -> mod_fastcgi -> FLUP (via CGI protocol) -> Django (via WSGI protocol) Flup is another way to run with wsgi for any webserver that can speak FCGI, SCGI or AJP

What is FLUP? What is AJP? How did Django come in the picture?

These questions raise quetions about PHP. How is it actually running? What technology is it using? mod_php & mod_python what are the differences?

In future if I want to use Perl or Java then again will I have to get confused? Kindly can someone explain things clearly and give a Complete Picture.

like image 442
claws Avatar asked Mar 28 '10 09:03

claws


4 Answers

The standard way to deploy a Python application to the web is via WSGI. These days there's no reason to use anything else.

mod_wsgi is the Apache module that supports WSGI. Other web servers will have different names for their WSGI modules.

like image 104
Daniel Roseman Avatar answered Nov 17 '22 14:11

Daniel Roseman


There is no exact equivalent to mod_php in the Python world.

  • FastCGI, SCGI, and AJP run the web app as a separate process (daemon), and pass messages between the web server and it.
  • mod_python is used to embed Python code into the httpd process during any of the request phases.
  • mod_wsgi can run Python code in either daemon or embedded mode.
  • CGI is a protocol that runs a script/program every time a request is made.
  • FLUP is a set of adapters that can be used to convert one of those interfaces to another.
like image 40
Ignacio Vazquez-Abrams Avatar answered Nov 17 '22 14:11

Ignacio Vazquez-Abrams


mod_python is the closest equivalent of mod_php, but this doesn't mean that mod_python will suit your needs. For each programming language you have to enumerate all the possible options and choose the one you'll need.

For PHP, you have mod_php and mod_cgi, but from this two mod_cgi is inferior in almost all ways to mod_php so people usually choose the latter. (There are some alternatives, like suphp if you need more security, etc.)

For Python you have mod_cgi, which will run the python interpreter each time you make a request. Mod_python instead has python embedded so it's usually faster and simpler to do, but for large projects, or projects that are using a framework (like DJango) you will probably want to use mod_wsgi because it is the most resource-friendly.

For ruby you also have the option to use mod_cgi, but that will be way too slow. mod_ruby is also an option, but only for small programs. mod_fastcgi was usually the option for rails/merb and other ruby based web frameworks, but they are superseeded by mod_rails and mod_rack, which are esource-friendly. But for simple scripts the latter are a bit too heavy-weight.

For mono (asp.net) you have mod_mono, which is usually the only option.

For java you usually run a separate Tomcat/Jetty web server, and use mod_proxy.

Of course running a separate web server and use mod_proxy is usually an option for all the web frameworks, although it is mostly suitable for the development process only. For production environments you have to choose carefuly the best option (the one which is the mostly resource-friendly) your framework (django,rails,asp.net,etc.) needs

like image 4
SztupY Avatar answered Nov 17 '22 14:11

SztupY


mod_python is the most like mod_php in what it does (ie. it tries to do everything). That's not necessarily a good thing and I wouldn't recommend writing applications to the native mod_python interfaces today.

WSGI is some kind of optimized/improved inshort an efficient version specifically designed for python

The difference is WSGI is defined in the Python language itself: it specifies what objects and values your code will receive. [S|Fast]CGI are more concerned with bytes on the wire.

By writing your application to the WSGI standard (either directly, or using a framework that supports it), you are uncoupling the concerns of application-writing and deployment.

In order to use this mod_wsgi is a way to go. right?

It's a way to go, and definitely a good choice for Apache users, but far from the only one. Write to WSGI and you can deploy in a wide range of environments, including [S|Fast]CGI and mod_python.

like image 2
bobince Avatar answered Nov 17 '22 14:11

bobince