Summary: There are many examples of Apache Python mod_python installed on Windows, tutorials and even illustrations, but as a novice it can be a mistake and cannot be quickly resolved. In this author will be based on their own practical experience, give a few places to pay attention to, to summarize the self, convenient for everyone!
PS: If you are interested in Mod_python installation on Linux, then even if you do, I believe you will not encounter too much trouble!
1 Confirm the installation version: currently recommended are apache2.2 + python2.5 + mod+python3.3; Note that this is all about the large version number, which is usually the first and second digits of the version number. The choice of such a combination of versions, mainly considering the Mod_python version, because we generally download after this:
Python code
1.<strong><span >mod_python-3.3.1.win32-py2.5-apache2.2.exe </SPAN>
2.
3.</strong>
If you're really a rookie and you're worried about making a mistake, then it's recommended that you stop or even uninstall the Apache service currently on Windows, and then install the required version; As for Python, you don't have to uninstall, just install another version, Then modify the system environment variable path to use the Python version you need!
2 Installation Order: This is really not necessary, the purpose of the list is just a reminder; the focus is on the installation process:
(1 after installing Apache, start, and access http://localhost or http://127.0.0.1 , see the success of the screen can be;
(2 then install Python, after completion set the system environment variable path, open a CMD window, successfully run Python can be;
(3 installing Mod_python, after successful installation, two things need to be done :
Re-enter Python>>>,import Mod_python to see if it is successful, or enter Help () and enter modules to check for Mod_python in the list that appears;
Two after the installation of the Mod_python, the confirmed mod_python.so in the Apache modules subdirectory, if not please manually copy.
3 load Mod_python, configure the test app to open Apache conf/httpd.conf:
(1 after a multiline LoadModule record, add the following statement to load the Mod_python
Python code
1.<strong># add by Gentleyang for Mod_python
2.LoadModule Python_module modules/mod_python.so</strong>
Please restart Apache at this time, if it is successfully started and can still be accessed successfully, load Mod_python is successful; If you want to view the load record, you can browse Apache log files!
(2 Create a new testmp directory in Apache's Htdocs subdirectory, where you create a new hello.py with the following content:
Python code
1.from Mod_python Import Apache
2.
3.def Hello_handler (req):
4. Req.write ("This was a ' Hello world ' from Mod_python!")
5. return Apache. OK
After that, find the httpd.conf <directory> tag, in which the following configuration of the test application is added:
Python code
1.# Add by Gentle Yang for testmp with Mod_python
2.<directory "D:/xxx/server/apache software foundation/htdocs/testmp" >
3.AddHandler Mod_python. py
4.PythonHandler Hello
5.PythonDebug on
6.</directory>
At this point, the test application configuration is complete!!!
Next, despite restarting Apache, then visit http://localhost/testmp/hello.py;
If an error occurs, check the log, or start from cmd using start, the console will print out a specific error message!
Errors that may occur include:
1 <directory> the contents of the tag are preceded by a space, which makes it impossible to find the configured handler;
2 hello.py script file is encoded incorrectly, or contains special characters such as full-width space, etc. if you cannot troubleshoot the error, first try to remove the configured <directory> tag, restart Apache to see if it is successful, and reconfigure!
Note that every time you modify the httpd.conf before you make a good habit of back-up, modify the best use of Notepad and other tools! I hope you can see the page containing the following words.
Python code
1.This is a "Hello world" from Mod_python!
Install Apache Python mod_python on Windows