-1

I'm on Mac OS X 10 Yosemite, so I'm wondering if others experience the same problem. This code gives you an insight into the problem. Make an index.php file, and this inside:

<?php
$exec = "diskutil list";
echo $exec;
$output = shell_exec($exec);
echo $output;

This is when using the built-in Apache + PHP version. When using XAMPP or Nightrain, it has no problem running the command above. So I'm wondering if the Apache or PHP version of OSX blocks certain shell_exec commands?

My experience so far:

When I type in the command-line the following command:

diskutil info /dev/disk1s1

I get a full overview of the disk information.

But when I use shell_exec() to execute the same command in PHP on OSX I get an error:

Could not find disk: /dev/disk1s1

Apache is configured to use the same ownership as my user (User:staff) - and all other commands work.

Also when I use the following command in the command-line:

diskutil list

I get a full overview. But then again shell_exec() is not returning anything, and in the Apache error log I see:

Could not start up a DiskManagement session

I Googled and found zero results.

Taapo
  • 1,785
  • 4
  • 18
  • 35
  • When I use PHP-Nightrain to run the commands, I don't have the same problems as described above. – Taapo Oct 24 '14 at 21:44

1 Answers1

0

First, your command line command is one thing, but the command in your PHP script is another. Meaning your command line examples are:

 diskutil info /dev/disk1s1

But the command in your PHP script leaves out the disk /dev/disk1s1 like this:

 diskutil list

So unclear what you are doing that is not working. Also, often in PHP scripts you need to set the full path for any binaries that are being called. So instead of this line:

$exec = "diskutil info";

Change it to this; note I added /dev/disk1s1 so the command has a disk to act on:

$exec = "/usr/sbin/diskutil info /dev/disk1s1";

And that is the location of diskutil on my Mac OS X 10.9.5 setup. To make sure it would be in the same path, use which like this:

which diskutil

Which would return something like this:

/usr/sbin/diskutil

And when I run it from the command line, I am doing it like this; assuming the test file is named shell_exec_test.php:

php ./shell_exec_test.php
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
  • I tried that - to no avail. It gives the same problem. Also with the fixed command (which I also corrected in the question). – Taapo Oct 26 '14 at 07:26
  • @Taapo Read my latest edit. Look at the examples you yourself are providing for the command line versus what is in the script itself. You left out `/dev/disk1s1` in your PHP script. – Giacomo1968 Oct 26 '14 at 07:28
  • Sorry, I was editing the question before to list "diskinfo list", but someone else was editing the question as well (admin?) so my question got set back to the original and faulty "diskutil info" – Taapo Oct 26 '14 at 07:30