How to set up XAMPP to run Python programs and php on your own computer. SQL works also. Only tested on windows 10.All programs can be run through localhost in browser and files stored in htdocs directory in xampp.
Xampp Version 5.6.30
Python.3.6.1

Link to Python

Link to XAMPP

Should be the same versions as mine in order to work.

Make sure to save Python as C:Python3.6 using custom installation.First line of your program must direct to where python.exe is installed.Mine is #!C:/Python3.6/python.exe .You must use parenthesis with print.

Instructions:
__________________________________________________________________
1.Install xampp and python, make sure to remember the location where everything is installed.Mine are in 1 folder.
2.When both are installed, run XAMPP.
3.add test files to htdocs mine are downloadable.
4.Open the httpd.conf file in apache by clicking config but do not start apache yet.
6. Look for AddHandler cgi-script .cgi .pl .asp and add .py to it
7.Start apache
8. open a browser, type localhost and go to it. This is your homepage.
9. To run your files type localhost/ enter in name of file. eg
localhost/hello.py
10. That’s it, it should work. Just make sure to have correct shebang on top of python files which shows the location of where python.exe is. Mine is #!C:/Python3.6/python.exe
11. You now should add passwords and run it offline if needed.
12.Python files need print(“content-type: text/htmlnn” ) below shebang in order to work.

my httpd file :

Python test program :

Php test program :

Program to run in idle to find path for shebang. Just add #! before it and double check it says python or python.exe if not just change it to the result of idle program.

Nguồn: https://codeigniterbrasil.com

Xem thêm bài viết khác: https://codeigniterbrasil.com/lap-trinh-php/

23 Comments

Suru_Kro

May 2, 2020

Internal server error in python?? End of script output header before .py file??
Are you running XAMPP -server?
Want to solve… Then go there https://youtu.be/NYevQUGexRo

Reply

Shubhamkar Joshi

May 2, 2020

couldn't create child process: 720005
Im getting this error. Culd you help?

Reply

Goldensparrow Mobile

May 2, 2020

thnaks

Reply

Ageim

May 2, 2020

it just show the code
#!c:/Python3.6/python.exe

print("Content-type: text/html")

print("""

<title> a </title>

<h1> hi</h1>

hello

""")

Reply

SHADOW

May 2, 2020

Working

Reply

Mithzy Nelson

May 2, 2020

You saved my butt!! Thanks!!

Reply

Shivam Singh

May 2, 2020

Bro It Works! Only I need to replace the path '#!C:/Python3.6/python.exe' to '#!C:UsersroxxshivamsinghAppDataLocalProgramsPythonPython37python.exe' it depends upon where your python interpreter is install check properly and copy path and paste it on the top of the page in comment using '!' symbol…

Reply

Bruno Souza

May 2, 2020

it doesnt working

Reply

prajwal kumar

May 2, 2020

but mysql module error is cmng fr me…..rest it works for me.

Reply

Steven Choo

May 2, 2020

if Python3.6.1 does not work, then try to download Python2.7.15 (Window users).
I solved my problem by doing this step.

Reply

chanchal dhingra

May 2, 2020

not able follow after localhost

Reply

Junaid khan

May 2, 2020

Working Great 🙂 Even on newer version.
Kindly I have a quaestion, How can I run that .py file from within the php file?

Reply

Peter Bennett

May 2, 2020

Ok guys, a couple of things you should remember…. when telling the script where your python file is located, make sure you use FORWARD slashes not back slashes, and make sure you point to the .exe not the root directory!! Worked for me, actually impressed at how simple it is!!! If this works when I deploy, I will be even happier!

Reply

TrashPanda

May 2, 2020

works thanks!

Reply

MImran Khan

May 2, 2020

Not working

Reply

Mostafa Abu Gheda

May 2, 2020

What is the name of this track in the video ? 😀

Reply

RoadracerSLO

May 2, 2020

tnx mate, just what I needed 🙂

Reply

Martin Brant

May 2, 2020

Hi, any chance you could give a link to your Python code? Is this Python 2 or 3? Thanks

Reply

Pandula Perera

May 2, 2020

Great!!!

Reply

FIRDOUS BHAT

May 2, 2020

how come dude ? Simply you placing python program in htdocs and it works ?

Reply

Kapil Saran

May 2, 2020

thxx man

Reply

radika watterson

May 2, 2020

hey jason , i'm from indonesia. i can't running my python on my lampp. do you have any tutorial ?

Reply

Atul Varshney

May 2, 2020

Hey Jason Cheung.. your video does work and it's appreciable.. but I'm stuck in running python script. Actually if i run simple python script like "Hello Python"with html tag then it does work,if i used only python script code that doesn't work , actually i want to get current URL using python script then how to do this. first of fall let me tell you. I'm getting the "Server Error!"

So finally i just wanna say how to write any python script. because previous script has with html tag not python coding at all. So Please get me the solution. I hope you are able get me .. what i wanna ask?

Reply

Leave a Reply