开发者

Can't run shell script from php web script

开发者 https://www.devze.com 2023-03-18 04:02 出处:网络
I am trying to run a shell script from a php script. I have complete control of the environment (unix on mac), I should have all the permissions, etc. set correctly.

I am trying to run a shell script from a php script.

I have complete control of the environment (unix on mac), I should have all the permissions, etc. set correctly.

The web script is in /htdocs/

The shell script can be executed from anywhere so when I go to /htdocs/ in the shell, I can easily run it like this: $ my_shellscript

.. but when my php script (which is located in开发者_运维百科 htdocs) tries to call it:

shell_exec('my_shellscript');

I get nothing.

I have proven the script can be called from that location and I have temporarily granted full access to try to get it working somehow. I am going crazy, please help.

If you know of some other way of triggering a shell script via the web that would be fine.

Thanks in advance.


well i got few weeks same problem, the solution is to check if the apace has the permission to execute your script. You could also try to run the script in php cli.


Since it is a shellscript, it needs to be invoked with the path prefix. My guess is you need to do this:

shell_exec('./my_shellscript');


First thing: make sure php isn't running in Safe Mode

Next thing: Try running it with the exec() function and using the full path (e.g. /var/www/htdocs/my_shellscript)


Try doing

echo shell_exec('my_shellscript 2>&1');

which will capture the script's stderr output and print it out. If something inside the script is failing, this output would otherwise be lost when not being run interactively.

0

精彩评论

暂无评论...
验证码 换一张
取 消