Using Apache HTTP Server on Microsoft Windows. Start Apache in Console placed to Start Menu - Programs - Apache HTTP Server 2.4.xx - Control Apache Server during the installation. This will open a console window and start Apache inside it. If you don't have Apache installed as a service, the window will remain visible until you stop.
i would like to briefly share my experiences withinstalling mod_python on a w2000 box. i must say that i
believe the installation process to be unnecessarily
complicated by the simple fact that the installer itself
seems to be buggy -- in my case, no combination of
mod_python 3.0.4, 3.1.2b and python 2.2.3, 2.3.3 ever
came to completion. rather, the installer would exit --
after an initial declaration of having successfully
found python in the registry -- with the words that it
'could not load python'. i now believe this may be due
to python being absent from ``path`` and a missing value
in ``pythonhome`` (see below), but on the other hand,
all my other package installations with this particular
installer brand had never given me any troubles. it
would be a nice thing if the installer was smart enough
to dispense some hints in such a case.
it is important to check that the correct python version
is selected for the respective version of mod_python --
as far as i can see, both 3.0.4 and 3.1.2b are built for
python 2.3, which at least in the former case is not so
clear from descriptions or filenames. whatever version
you downloaded, you can quickly check this by 1)
unpacking the ``*.exe`` file with a zip tool, 2) go to
the contained folder ``DATA``, open the binary
``mod_python.so`` in any text editor, and 3) search for
the string ``python2``. this should yield a single hit,
from which you can glean the expected version of the
python dll. since i never managed to finish the
installation process with the installer, i think it is
the best idea to then proceed like this:
1) simply grab that ``python_mod.so`` file and drop it
in the ``apache/modules`` folder; likewise, go to the
directory ``PURELIB/mod_python`` in the executable
archive and copy it as ``python/Lib/site-
packages/mod_python``.
2) in apaches ``httpd.conf``, do a test configuration
like this::
# NB.: When setting an alias, both the alias
# and the aliased location should end in a
# slash or avoid it.
Alias /mod_python0 'drive:/some/path/mod_python/test0'
<Directory 'drive:/some/path/mod_python/test0'>
Options Indexes
AddHandler python-program .py
PythonHandler myhandler
PythonDebug On
</Directory>
observe that ``.py`` does start with a dot -- this does
not seem to be essential, though.
one important point is that you had better make sure
that python scripts are not declared as cgi scripts in a
parent directory. if you absolutely need this, try
later, but for the moment it is important to understand
that the ``ExecCGI`` and the ``python-program``
declarations are enemies. -- restart apache (must be
version 2, btw, afaics), either from the services
management console, or, much better, from a terminal
window by saying
apache.exe -k restart
(if you have your apache installed as a service). the
terminal window method has the distinct advantage that
any error messages due to problems with the httpd.conf
do appear right in front of your eyes, instead of being
silently swallowed by the system. of course, you can
also simply start apache as an ordinary program with a
line like ::
apache -w -f drive:pathtoapacheconfhttpd.conf
3) create .../mod_python/test0/myhandler.py and make
it contain something like this::
#
# -*- coding: utf-8 -*-
from mod_python import apache
def handler(req):
req.content_type = 'text/plain'
req.write('Hello World!')
return apache.OK
observe that the ``import`` statement prohibits the
execution of this snippet as a script, since it causes
the import of a module that is only available from
``mod_python.so`` -- maybe someone can come up with a
good idea how to make mod_python web scripts executable
from the command line some day; developers will love
that.
4) in case the directory where the pythonXX.dll is to be
found should *not* appear on the environment variable
``path``, apache will refuse to start and issue the
following message::
Cannot load drive/dir/Apache2/modules/mod_python.so
into server: The specified module could not be
found.
this may be a problem with per-user python installations
that put the dll into the python directory, not into the
windows directory.
5) you also may want to consider setting the
``pythonhome`` environment variable -- while
experimenting, this solved my problems in one case, but
for some reason, i found myself unable to reproduce the
behavior later. anyhow, you'd simply type ::
set pythonhome=drive:pathtopython
or create an entry in ``autoexec.bat``, or set the
variable in the system administration.
6) one user also mentioned insufficient access rights in
the scripts directory as a potential cause of
malfunction -- apache does ordinarily not run as a
common user, but under a special account that must be
granted execution access to the directories where you
deploy your web application (i did not have his problem,
but may be this is due to apache running with
administrator rights, which is not a brilliant idea to
boot).
7) enjoy.
greetings,
_wolf
Installation (Python 2.5.1 + mod_python 3.3.1 + Apache 2.2.6)
1.Install Python 2.5.1
2.Install Apache 2.2.6
We choose to install the Apache server as a system service.
At the end of installation process, the installer will create default configuration files, the firewall software may block that action, we’d better to shutdown the firewall application before installing Apache
3.Install mod_python 3.3.1
At the end of installation process, the installer will ask you the Apache directory, then it will install mod_python.so to the APACHE_ROOT/modules directory
Configuring & Testing
We will use the default document root directory (APACHE_ROOT/htdocs)
1.Following the direction of mod_python manual, add following line to Apache configuration file (APACHE_ROOT/conf/httpd.conf)
2.Add the following Apache directives,
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
3.This redirects all requests for URLs ending in .py to the mod_python handler
4.Restart Apache in order for the changes to take effect
Troubleshooting: Failed to restart apache server
Use Event Viewr to find out the problem:
In System Event say:
The Apache2.2 service terminated with service-specific error 1 (0x1).
In Application Event say:
Apache/conf/httpd.conf: Cannot load
Apache/modules/mod_python.so into server: The specified module could not be found.
From the python interpreter, we can import mod_python successfully, why? mod_python.so use python25.dll, and our user path variable already contain the Python directory; We start the Apache server as a system service, it will use the system path variable to find the import dll files; So we should add the Python directory to the system PATH variable
Edit mptest.py file in the APACHE_ROOT/htdocs directory so that is has the following lines
from mod_python import apache
def handler(req):
req.content_type = 'text/plain'
req.write('Hello World!')
return apache.OK
5.Point your browser to the URL referring to the mptest.py(for example, http://localhost/mptest.py); you should see 'Hello World!'.
Troubleshooting: No “Hello World!”
From APACHE_ROOT/log/error.log say:
[error] make_obcallback: could not import mod_python.apache.n
[error] make_obcallback: Python path being used '['C:Pythonpython25.zip', '.DLLs', '.lib', '.libplat-win', '.liblib-tk', 'C:Apachebin']'.
[error] get_interpreter: no interpreter callback found.
[error] [client 127.0.0.1] python_handler: Can't get/create interpreter.
Apache server cann’t import mod_python.apache, we should add a PYTHONPATH system variable to contain the python modules path, for example, we can set it as following
C:Python;C:PythonDLLs;C:PythonLib;
C:PythonLiblib-tk;C:PythonLibsite-packages