exec/system() - script being called works until called from PHP
-
05-06-2021 - |
Question
I have a bash script:
run.sh
#!/bin/sh
cd /var/www/project/bin/
CMD="./executable <full_path_to_file>;
$CMD
When I run this program from the terminal. (i.e. ./run.sh
, it works fine)
However when I call it from PHP:
system("full_path_to_sh_file", $out);
It calls the script successfully, and even runs the executable, but now the executable throws an error saying that the supplied file can't be found.
Any ideas?
La solution
- How do you run PHP script, from webserver or command line?
- If from webserver, what user is it run (httpd or apache?)
- Make sure the environment as same as when you are running from terminal (for example: same user)
- Try this if running as different user:
sudo -u apache /fullpath/run.sh
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow