Saturday, December 14, 2013

Converting XAMPP into XAMPPP

This tutorial explains about a simple method to configure Apache, PHP, MySQL, Perl and Python in windows platform. In this tutorial, I have used the latest operating system (Windows 8.1 Enterprise Edition 64-bit) and latest softwares - XAMPP 1.8.3 and Python 3.3.0. Refer official site of XAMPP and Python for installation instructions.

XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. The XAMPP 1.8.3 contains of Apache, MySQL, PHP + PEAR, Perl, mod_php, mod_perl, mod_ssl, OpenSSL, phpMyAdmin, Webalizer, Mercury Mail Transport System for Win32 and NetWare Systems v3.32, Ming, FileZilla FTP Server, mcrypt, eAccelerator, SQLite, and WEB-DAV + mod_auth_mysql. The default configuration of Apache is perfectly linked with MySQL, PHP and Perl. Since Perl and Python run under common gateway interface (CGI), configuring Python CGI with XAMPP is very easy. To convert XAMPP into XAMPPP, we have to change the existing AddHandler Apache configuration command to

AddHandler cgi-script .cgi .pl .asp .py

in httpd.conf file, which is located in "C:\xampp\apache\conf".


httpd.config

Next step is to create a Python CGI script with the path of the Python directory (C:\Python33) mentioned at the first line and save the script in the directory (C:\xampp\cgi-bin) with the file extension .py. An example of a Python CGI script is given below:

Source Code: test.py
#!C:\Python33\python.exe
print("Content-type: text/html\n")
print("<html>")
print("<head><title>Hello Python</title></head>")
print("<body>")
print("<h2>Hello Python.</h2>")
print("</body>")
print("</html>")
Now open the web browser and enter the url as 127.0.0.1/cgi-bin/test.py. You should have a working page as given below.


Hello Python

Note: The first two lines are compulsory (change the first line according the path of installed Python directory). Print statement must be entered with rounded brackets as print("Hi").

1 comment :