The problem is not with your code or PHP.
The problem is with your permissions.
php uses the permissions set in env-vars apache.
Which is perfect like:
User ${APACHE_RUN_USER} Group ${APACHE_RUN_GROUP}
in your apache2 / httpd conf file.
For instance:
Try to run:
<?= `whoami` ?>
through your shell and through your browser.
Your browser will probably say that www-data and shell will say your username or if you are on AWS - by default you will get root
You do not need to use system() , use exec() instead.
We should be close like:
echo json_encode(exec("python --version"));
To complete the operations, you will need to install the correct set of users and groups.
Seek: In a shell, what does "2 & 1" mean?
So your code should be:
echo json_encode(exec("python --version 2>&1"));
Hope this helps!
source share