dataskills
dataskills

Reputation: 656

Can't run shell script from php web script

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.

Upvotes: 2

Views: 3734

Answers (4)

Marc B
Marc B

Reputation: 360842

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.

Upvotes: 0

Clint
Clint

Reputation: 2891

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)

Upvotes: 0

thunderflower
thunderflower

Reputation: 181

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');

Upvotes: 0

Risto Novik
Risto Novik

Reputation: 8295

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.

Upvotes: 1

Related Questions