473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Apache web server and CGI

Lad
How can I set up Apache web server to use Python for CGI processing( for file *.py).
Thanks for help
Lad
Jul 18 '05 #1
7 41546
Lad wrote:
How can I set up Apache web server to use Python for CGI processing( for
file *.py). Thanks for help


A simple method would be to include the line:

AddHandler cgi-script .py

in your httpd.conf. This should work fine so long as your .py files start
with a proper invocation of the python interpreter (i.e.,
#!/usr/bin/python). You might also want to look at mod_python
(http://www.modpython.org/).

Jeffrey
Jul 18 '05 #2
In article <81*************************@posting.google.com> , Lad wrote:
How can I set up Apache web server to use Python for CGI processing( for file *.py).
Thanks for help
Lad


I will assume you have cgi working in apache in cgi-bin. I will also assume
that you want to use it on *NIX. You didn't tell and I don't know how to do
it on windows ;-)

The simplest thing that should work is sth like this:

Create a file: test.py

---------------------------------------
#!/usr/bin/env python

print "Content-Type: text/html"
print
print """
<html>
<head>
<title></title>
</head>
<body>
Hello Lad!
</body>
</html>
"""
----------------------------------------

Now do:

chmod 755 test.py

And then go there with a browser:

lynx http:/localhost/cgi-bin/test.py

Hth,

PterK

--
Peter van Kampen
pterk -- at -- datatailors.com
Jul 18 '05 #3
Lad
Jeffrey Froman <je*****@I.slack> wrote in message news:<10*************@corp.supernews.com>...
Lad wrote:
How can I set up Apache web server to use Python for CGI processing( for
file *.py). Thanks for help


A simple method would be to include the line:

AddHandler cgi-script .py

in your httpd.conf. This should work fine so long as your .py files start
with a proper invocation of the python interpreter (i.e.,
#!/usr/bin/python). You might also want to look at mod_python
(http://www.modpython.org/).

Jeffrey


Thank you Jeffrey and Peter for help.
I added AddHandler cgi-script .py to httpd.conf
I also tried to run the test script as Peter suggested but the Apache
says( in error log)

[Tue Aug 10 08:51:32 2004] [error] [client 127.0.0.1] (2)No such file
or directory: script not found or unable to stat: c:/program
files/apache group/apache/cgi-bintest.py

The name of script is test.py and is in cgi-bin (Apache subdirectory).

I tried to run the script from IE browser with the command
http://localhost/cgi-bin/test.py

but without success. I use XP home edition.

Apache runs without problem as I could check it by inserting
http://localhost/

BTW, how can I set up a different directory for cgi scripts? For
example I would like to have all my scripts in
C:\Scripts\MyScripts

Thank you for help
LAd
Jul 18 '05 #4
In article <81************************@posting.google.com>, Lad wrote:
[Tue Aug 10 08:51:32 2004] [error] [client 127.0.0.1] (2)No such file
or directory: script not found or unable to stat: c:/program
files/apache group/apache/cgi-bintest.py

The name of script is test.py and is in cgi-bin (Apache subdirectory).
In my experience cgi-bin is rarely just a subdir of apache's www-root. The
name cgi-bin is in itself not some magical name that 'turns CGI on'. You
have to configure it on your httpd.conf. Here's a relevant bit of mine:

#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

#
# "/usr/lib/cgi-bin" could be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory /usr/lib/cgi-bin/>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

Also just to be sure the first line of test.py should be sth like this on
windows:

#! c:\path\to\python.exe
BTW, how can I set up a different directory for cgi scripts? For
example I would like to have all my scripts in
C:\Scripts\MyScripts


This is probably clear by now...

Hth,

PterK

--
Peter van Kampen
pterk -- at -- datatailors.com
Jul 18 '05 #5
Lad
Peter van Kampen <ne**@woody.datatailors.com> wrote in message news:<slrnchhcv5.mtn.ne**@woody.datatailors.com>.. .
In article <81************************@posting.google.com>, Lad wrote:
[Tue Aug 10 08:51:32 2004] [error] [client 127.0.0.1] (2)No such file
or directory: script not found or unable to stat: c:/program
files/apache group/apache/cgi-bintest.py

The name of script is test.py and is in cgi-bin (Apache subdirectory).


In my experience cgi-bin is rarely just a subdir of apache's www-root. The
name cgi-bin is in itself not some magical name that 'turns CGI on'. You
have to configure it on your httpd.conf. Here's a relevant bit of mine:

#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

#
# "/usr/lib/cgi-bin" could be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory /usr/lib/cgi-bin/>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

Also just to be sure the first line of test.py should be sth like this on
windows:

#! c:\path\to\python.exe
BTW, how can I set up a different directory for cgi scripts? For
example I would like to have all my scripts in
C:\Scripts\MyScripts


This is probably clear by now...

Hth,

PterK

Thanks Peter for help. Now I can run cgi scripts in default
c:/program files/apache group/apache/cgi-bin/
directory.
The problem was that there was not last "/"

But how can I forced the Apache to allowed to run scripts in a
different directory for example C:\Test\MyScripts\
Thanks for help
Lad
Jul 18 '05 #6
In article <81*************************@posting.google.com> , Lad wrote:
<Directory /usr/lib/cgi-bin/>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
Thanks Peter for help. Now I can run cgi scripts in default
c:/program files/apache group/apache/cgi-bin/
directory.
The problem was that there was not last "/"

But how can I forced the Apache to allowed to run scripts in a
different directory for example C:\Test\MyScripts\


I would guess you have something like the above in your httpd.conf

ScriptAlias /cgi-bin/ c:/program files/apache group/apache/cgi-bin/

<Directory c:/program files/apache group/apache/cgi-bin/>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

Simply replace c:/program files/apache group/apache/cgi-bin/ with
C:\Test\MyScripts

Hth,

PterK
--
Peter van Kampen
pterk -- at -- datatailors.com
Jul 18 '05 #7
Lad
Peter van Kampen <ne**@woody.datatailors.com> wrote in message news:<slrnchk875.p2u.ne**@woody.datatailors.com>.. .
In article <81*************************@posting.google.com> , Lad wrote:
<Directory /usr/lib/cgi-bin/>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

Thanks Peter for help. Now I can run cgi scripts in default
c:/program files/apache group/apache/cgi-bin/
directory.
The problem was that there was not last "/"

But how can I forced the Apache to allowed to run scripts in a
different directory for example C:\Test\MyScripts\


I would guess you have something like the above in your httpd.conf

ScriptAlias /cgi-bin/ c:/program files/apache group/apache/cgi-bin/

<Directory c:/program files/apache group/apache/cgi-bin/>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

Simply replace c:/program files/apache group/apache/cgi-bin/ with
C:\Test\MyScripts

Hth,

PterK


Peter, Thanks a lot. Now it works, but the scripts must be still
started as
http://localhost/cgi-bin/test2.py eventhough the scripts are not
/cgi-bin/ directory but in MyScripts directory. I think that Apache
maps MyScripts directory to /cgi-bin/ directory.
Thanks again for help
Lad
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steven | last post by:
I actually have two questions: 1. I try to get current time, but the time I got is 1 hour different from my local time. I assume it is caused by Time Zone. So is there any easy way to fix this?...
7
by: kecebong | last post by:
I installed php-4.3.3, mysql and apache server 2.0.47. but I can not connect to my apache server from my other computer, i use static ip for my server, set ip address for server name on httpd.conf,...
1
by: Kim Gijung | last post by:
Hi all, I'm wondering how the apache server and php interepreter handles request. If one request comes to apache server what is next procedure? if apache server passes the request to php...
1
by: PerryG | last post by:
We have a .NET 1.1 client which is sending a gzipped soap request using HttpWebRequest to an Apache server. The Apache server is using a the 'mod_deflate' server to decompress the incoming...
5
by: PerryG | last post by:
We have a .NET 1.1 client which is sending a gzipped soap request using HttpWebRequest to an Apache server. The Apache server is using a the 'mod_deflate' server to decompress the incoming...
14
by: Jim Carlock | last post by:
I have a couple easy questions possibly. 1) Is there a default.php page? The webserver seems to support default.htm, default.html, index.htm and index.html. It's an Apache server, I'd like to...
6
by: kalyan.muppala | last post by:
Hi all, Presently I have Windows XP Home edition and there's no IIS in it...Should I install XP Professional to get the IIS or is it fine if I proceed with Apache..?? Will .NET run on Apache...
1
dmjpro
by: dmjpro | last post by:
i am new to apache server ...... how this is configured .... and how does it work when an web-application is deployed ...... one more thing .... seperate me application server and web server....
2
by: dineshshank | last post by:
Hello , I have installed Apache Server 2.2.4 as instructed by Bugzilla .Why Apache Server is preferable .And why not Internet Explorer. And which way Apache can be...
5
by: senadslipac | last post by:
How to Q: Uncompressing ~400K files on Apache Server Hello All, I have ~400K html files on my local XP machine and I’d like to compress the files, upload them onto my host (apache - pair.com)...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.