I am using PHP and XAMPP
. I have enabled port localhost:8080
and I want to execute a python script (Main.py
) from my PHP script (index.php
). My PHP script is located at:
/Users/User/.bitnami/stackman/machines/xampp/volumes/root/htdocs/index.php
and the Python script is located at:
/Users/User/.bitnami/stackman/machines/xampp/volumes/root/htdocs/Main.py
.
My Python script is the following:
print('Hello World')
My PHP script is the following:
<?php
$output = exec('/usr/local/bin/python3 /Users/User/.bitnami/stackman/machines/xampp/volumes/root/htdocs/Main.py ' . ' 2>&1');
var_dump($output);
?>
(/usr/local/bin/python3
is the output of which python3
at the terminal)
However, the output that I am getting at localhost:8080
is:
string(40) "sh: 1: /usr/local/bin/python3: not found"
I have also tested different variations of my line with exec()
by writing for example exec('/Users/User/.bitnami/stackman/machines/xampp/volumes/root/htdocs/Main.py ' . ' 2>&1')
but nothing returns the right output.
What am I doing wrong and how can I fix it?
I am aware of similar posts on StackOverflow (Running a Python script from PHP, Can't execute Python script from PHP document, Python Script Failing to Execute from PHP exec(), How to properly call Python 3 script from PHP?) but none of this works as such for me.
I am wondering if my problem is related to the fact that I did not make any configuration to run the Python script on XAMPP
as it is described at some posts here (Running Python scripts with Xampp).