-1

in Debian 8, I'm trying to create a script I can put under /sbin (which is in my $PATH environment variable), so it can be run, the command is a simple echo of a few lines. I've created a bash script and made it executable, so I can run it from my terminals just like any other command, but I cannot run it from my PHP script, even though the $PATH environment variable is the same in my terminal and in my script, (i've verified it).

The script will be called ifconfig (and I know it's an obsolete program no longer around in debian 8, but I can't get around it for now, so I need a stub).

  • When I run ifconfig from the terminal, I get all my successful output .
  • When I run ifconfig from the script, I get a FALSE.
  • When I run a which ifconfig, the terminal outputs /sbin/ifconfig.
  • When I run a which ifconfig from a PHP script, it doesn't return any route.

How can I make this bash script work on PHP? shell_exec('ifconfig'); or how can I manuplate the particular output of shell_exec('ifconfig');

The script is running under apache-2.4

I'm posting this because I'm not sure this should be in Stack Overflow, Super User, or Server Fault.

Snivs
  • 101
  • 4
  • Why can't you just call it with its full path? Also you should be putting this sort of thing in `/usr/local/bin/`; don't mess with `/sbin/`. – miken32 Oct 27 '15 at 17:02
  • The script running the command is encoded with ionCube loader, and I don't have any original copies (the code was written about 10 years ago, and the person who wrote it left no copies), so modifying the actual call it's out of the question. – Snivs Oct 27 '15 at 17:08
  • 1
    Then check permissions on the executable; if selinux is enabled, check your audit log. – miken32 Oct 27 '15 at 17:10
  • The script you called from php script must be exec-able by the user that run php script, may be **apache**. – jasonz Oct 30 '15 at 16:10

1 Answers1

1

There are a couple of things you should pay attention to:

  1. Does your php.ini configuration file allow to use shell_exec()?
  2. Normally, all commands will be executed using the www-data user. Said that, you should check if the user can actually run the command in question. If you're in a system that uses sudo, that's a good way to allow it.
  3. Remember that when safe_mode is on, you can't use shell_exec().
  4. Your error.log and access.log file are great places to check what's going on, specially if you don't have display_errors turned on.

Cya!

Stefano Martins
  • 1,221
  • 8
  • 10
  • Thanks for your answer! My php.ini does allow to use shell_exec, i've chown'd the file so the apache user owns it now, and the apache group has access to it as well (yeah, my httpd runs with the user "apache"), Safe mode is off, I have display errors turned on, but there are no actual PHP errors displayed or in the configured PHP log. – Snivs Oct 27 '15 at 18:20
  • Actually, I had a typo in the user owning ifconfig... thanks a lot. – Snivs Oct 27 '15 at 18:42