The installation involves the following steps:
0. Prerequisites
You need to have the following packages properly installed and configured in your system:You need to download both the
- Python 1.5.2
- Apache 1.3
- Winzip 6.x or later.
mod_python.dll
and themod_python-x.tgz
(where x is the version number) files from the main page.
Once you have all the things above mentioned we're good to go.1. Installing mod_python libraries
- Use Winzip to extract the distribution file (
mod_python-x.tgz
) into a temporary folder (i.eC:\temp
):
NOTE: If Winzip shows this warning "Archive contains one file, should Winzip decompress it to a temporary folder?" just click on
Yes
, the content of the file should appear in Winzip right after.- Select all the files in Winzip and click on the Extract button, then type-in the path or just browse your way to the temporary folder and click
extract
.- Open your Windows Explorer and locate the temporary folder where you extracted the distribution file, you should have a new folder in your temporary folder (
C:\temp\mod_python-x
).
- Move (or just drag & drop) the
mod_python-x
folder into the Python lib folder (i.eC:\Program Files\Python\lib
).- Move the files in the folder
lib
inside themod_python
folder (C:\Program Files\Python\lib\mod_python-x\lib\mod_python
) to theC:\Program Files\Python\lib\mod_python
folder. It's safe to delete these folders we just emptied.2. Integrating it with Apache
Once the distribution file is correctly extracted and later moved into the Python directory, it's time to modify your Apache configuration (httpd.conf
) and integrate the server with mod_python. These are a few steps we must do first:
- Locate the file
mod_python.dll
that you downloaded before and move it to Apache'smodules
folder
(i.eC:\Program Files\Apache Group\Apache\modules
).- Go to the Apache configuration folder (i.e
C:\Program Files\Apache Group\Apache\conf\
) and edit thehttpd.conf
file.- Add the following line in the section
"Dynamic Shared Object (DSO) Support"
of the httpd.conf file:LoadModule python_module modules/mod_python.dll- Add the following lines in the section
ScriptAlias and CGI
of thehttpd.conf
:<Directory "<Your Document Root>/python"> AddHandler python-program .py PythonHandler test PythonDebug on </Directory> NOTE: Replace the <Your Document Root> above with the Document Root you specified on theDocumentRoot
directive in the Apache'shttpd.conf
file.- Last, create a folder under your Document Root called
python
.3. Testing
- Create a text file in the folder we created above and call it
test.py
(you can use Notepad for this).- Insert the following lines and save the file (Make sure it gets saved with the
.py
extension):from mod_python import apache def handler(req): req.content_type = "text/plain" req.send_http_header() req.write("Hello World!") return apache.OK- Make sure Apache is running (or launch it!) and then point your browser to the URL referring to the test.py, you should see
"Hello World!"
. That's it, you're ready to roll!! If you don't see the "Hello World!" message, the next section is for you.4. Troubleshooting
There are a couple things you can try to identify the problem:
- Carefully study the error output, if any.
- Check the error_log file, it may contain useful clues.
- Make sure Python and the mod_python files are correctly installed/extracted
- Ask on the mod_python list. Make sure to provide specifics such as:
. Your Windows version.
. Your Apache version.
. Relevant parts of the Apache config, .htaccess.
. Relevant parts of the Python code.