0

here is my code in control.php:-

<?php
$output = shell_exec("/var/www/script.py");
?>

why i cant run the shell_exec() command when i run the php script..? it should call the script.py and execute the py script.. but, when i run the control.php script..

note that i tried to run a normal program by using php where i tried to open gedit by using the command below:-

 <?php exec('gedit');?>

the gedit is not executed..

anyone can help me?

3 Answers 3

1

Can you run "/var/www/script.py" in the BASH? if NOT, then check the script,make sure contain the following line:

#!/usr/bin/env python

then chmod +x script.py to make sure it is executable.

Sign up to request clarification or add additional context in comments.

2 Comments

i can run the "/var/www/script.py" in the bash very well =) but not from the php itself..
have you disabled the selinux? the /var/www/script.py is usually a default folder for apache, you could run "getfacl" to check if the PHP interpreter has enough access to that script.
1

You probably need to specify python in shell_exec() explicitly:

$output = shell_exec("/usr/bin/python /var/www/script.py")

or

$output = shell_exec("python /var/www/script.py")

and you need to ensure that your script.py has a permission better than "-rwxrwxr-x" as your php probably is executed by a different user.

3 Comments

both cannot be run.. i may need a permission.. but how to get the permission and how to know which user is executing the php? i run the code using google chrome in linux..
@ShahAbdHafiz You type ls -ltr /var/www/script.py and then the first column you get is its permission
solved! it just doesnt have permission to run the write/read to py script in desktop.. i changed the directory to the same directory of the php.. everything runs smoothly.. thank you guys!
0

the reason is because of the php doesnt have the permission to write/read the py script in desktop.. so, just change the directory of the py to the same directory as the php file then eveything runs smoothly..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.