1. Download and Install XAMPP – make sure MySQL and Apache is running
2. Python – download and install it at python.org
3. Edit http.conf in your apache. Find: AddHandler cgi-script .cgi .pl .asp and add .py and save
4. Instal PIP in your machine
– download
Copy the code and put it somewhere in your computer.. and then go to file location via terminal.. then run following command:
sudo python get-pip.py
5. Then lastly install PyMYSQL
type this command: pip install PyMysql
6. Then restart your apache and Mysql
7. Create python file cgi-bin/hello/hello.py
cgi-bin folder is inside the XAMPP
8. hello.py
1
2
3
4
|
#!/usr/bin/python
print ("Content-Type: text/html\n")
print ('Hello Word - First CGI Program')
|
PHP was designed for web programming so it automatically attaches Content-type to HTTP headers but Python doesn't. Prepend this to main():
print "Content-Type: text/html\n"