Running CGI under apache without shebang? Or how to execute CGI on a server in a neutral way

Thus, I find myself in a strange situation when I need to understand how the old CGI (simple CGI) execution is executed on the Apache web server. Yes, I know, in a real installation we use the Apache or FastCGI module! But anyway...

As I understand it, the Apache CGI script looks like this (perl in this example, but could be anything):

#!/usr/bin/perl print "Content-type: text/html\n\n"; print "Hello, World."; 

This was borrowed from here: http://httpd.apache.org/docs/2.2/howto/cgi.html

Then you used the following apache directives to make sure that the perl scripts were executed as CGI:

 <Directory ...> ... Options +ExecCGI AddHandler cgi-script .pl </Directory> 

It's great. Note that Apache relies on shebang to force the interpreter to run script as.

In lighttpd's light, though, this works differently. In the server configuration, we explicitly specify which interpreter to use based on the extension for each file, for example:

 cgi.assign = ( ".php" => "/usr/local/bin/php", ".pl" => "/usr/bin/perl" ) 

If lighttpd is suitable for running a script using shebang, it seems to be ignored. Good.

My question is: is there a way to do something like this in Apache? Can I indicate which interpreter to use in the server configuration so that the scripts do not need shebang. Presumably, people did not (back when CGI was something else) add shebangs to each PHP file so that the application can be run in Apache / CGI.

I could not find the answer in the Apache docs. So maybe you canโ€™t do this?

EDIT: Also, whose responsibility is to send the Content-Type header. Did people manually output this in CGI days? I donโ€™t remember ever seeing a PHP script that did this.

Greetings

+6
source share

Source: https://habr.com/ru/post/974208/


All Articles