Install Python in C:\usr\bin

Will Stuyvesant hwlgw at hotmail.com
Wed Jan 15 13:13:14 EST 2003


++++++++++++++++++++++++++++++++
CGI development on Windows HOWTO
++++++++++++++++++++++++++++++++

So you want to develop CGI scripts at home on your Windows laptop? 
And you want to be able to just copy them to the cgi-bin directory on
your local ISP every now and then, without having to change lines of
code?
Well it is not that easy.  Actually it *is* easy but it takes a while
until you have everything configured just right.  To save you time and
as a reminder to myself (in case I need a new computer): I now have an
easy development process, here it is:



Get a CGI server on your laptop
===============================

Install Apache on your laptop, download the windows installer from
apache.org.  Find the "Configure Apache" link in your Start Menu
(below Apache Group), click on it.  You are in Notepad now; replace
the line

    Options Indexes FollowSymLinks MultiViews

with

    Options Indexes FollowSymLinks MultiViews ExecCGI

I have no idea why they do not give you a CGI enabled web server by
default but that is just the way it is with these *nix people.  It
doesn't matter how much time you lose because of things like this,
don't argue, be happy they give you a free web server :)



The directories
===============

Your CGI scripts go into:
-------------------------
C:\Program Files\Apache Group\Apache\cgi-bin

Rename python files that are CGI scripts:
you can use ``ren *.py *.cgi`` for those.
Keep the .py extension on modules you import.

For reasons explained later, your CGI scripts should all start with
the line
#!/usr/bin/python


Your HTML files go into:
------------------------
C:\Program Files\Apache Group\Apache\htdocs

In your HTML files you can get to your CGI script with:
``http://localhost/cgi-bin/yourscriptname.cgi`` in a FORM tag.
Note that this is a line in the HTML file you have to change before
you copy the HTML file to your local ISP, change it to:
``http://yourisp.com/~yourusername/cgi-bin/yourscriptname.cgi``
But after a while you will get tired of it and stop mixing HTML files
and CGI scripts, and generate all HTML you need with your CGI scripts.
 Inside your CGI scripts you do not need to specify
http://yourisp.com/~yourusername/cgi-bin/, but only the relative path
(from cgi-bin) to whatever you want to put in generated HTML tags. 
This is why you want your CGI server on your laptop to be very similar
to a real world web server at your CGI.  You are simulating your ISPs'
installation at home.  Which brings us to:



Install Python in C:\usr\bin
============================
I assume you have Python already installed in C:\Python22 and you do
not want to change it.
During re-install (of the latest Python version?), choose C:\usr\bin
as install directoy and when you see the Advanced button, click on it
and do Non-Admin install and choose *not* shortcuts and *no* .py
exe-extensions unless you want this new python version to replace your
existing python installation.



Calling CGI scrips directly with IE
===================================
Open your Internet Explorer and type in url:
http://localhost/cgi-bin/yourscriptname.cgi


Copying files to the cgi-bin directory at your local ISP
========================================================
Get scp.exe from GNU.org
Now:
C:\Program Files\Apache Group\Apache\cgi-bin\> scp yourfile.cgi
yourusername at yourisp.com:~/cgi-bin
Or use another copying method to get them there.

Now your CGI scripts are available via internet at
http://yourisp.com/~yourusername/cgi-bin/yourscriptname.cgi

This assumes that your ISP has python installed in /usr/bin.  This is
where for example sourceforge has python installed.  If your ISP does
not provide CGI or python (that would give "Internal Server Error"
messages), get another ISP :)



Crazy directory structures
--------------------------

Perhaps your ISP has python in /usr/local/bin/ or another weird place.
How to find out?
Get ssh.exe from GNU.org
Now:
C:\Program Files\Apache Group\Apache\cgi-bin\> ssh -l yourusername
machinename.yourisp.com
Call your ISP if you don't know a machine name you have access to.  Or
use any other way to get shell access, and type
``which python`` in the console box on their *nix system, this will
tell you where python lives.  Replace all "/usr/bin" stuff in this
HOWTO with whatever it returns.
Also for the location of cgi-bin of even your home they sometimes have
weird directory tree structures.

hth




More information about the Python-list mailing list