0

I want to execute a Python script from PHP and apparently there are two completely different methods to do it.

The first method is to install Python on Wampserver (which I am using). The method described here involves extra files (mod_wsgi) and some modification (httpd.conf). I tried this method and Wampserver started failing (localhost not available) which was resolved by removing mod_wsgi.

The second method is by simply using the shell_exec command (example) which executes the Python script without any problems. I was a little surprised at how easy it was to do it and I have no idea why it works. I assume that the shell used is that of the current server's. Does this mean that I can also use installed external libraries in that script (e.g. OpenCV / cv2)?

What are the differences between the two methods and why is method 1 so complicated?

Community
  • 1
  • 1
Dennis
  • 309
  • 1
  • 6
  • 17
  • 1
    as far as I know, the first method would not allow you to execute python scripts from your php code, but you will be able to serve a python wsgi application – gosom Sep 15 '14 at 13:34
  • What ultimately is it you want to do? Using mod_wsgi will allow you to develop a web application in Python. On there other hand, executing Python scripts from PHP will allow you to perform actions out of your existing PHP web application which happen to use Python for that small part of the work. – Graham Dumpleton Sep 16 '14 at 01:02

0 Answers0