Cannot Start Unity from PHP exec() method

I have a similar question here that I asked the other day, but thought I would post a second one for a more simple problem.

It seems I can get the PHP exec() method to open any Application on my Mac except for Unity (5 applications chosen at random of varying memory size all succeeded). It always crashes due to some mysterious exception that is posted to Apache’s error_log. The details of the exception are never included. A return code of 6 is always fed back to PHP as well, but there’s no way of knowing what return code 6 actually means.

If you are hosting a PHP server and are on a Mac, I invite you to please try and execute this PHP script on your server and to let me know if it works. If you are on a PC, you’ll just need to change the path to Unity.

Note: If you receive "Error #-5000 while verifying your authorization. Unknown error." while attempting to run this script, I was able to “fix” that by changing User and Group inside of /private/etc/apache2/httpd.conf to my username/group (instead of the default _www).

<?php
$retval = -1;
$output = null;

$program = "/Applications/Unity/Unity.app/Contents/MacOS/Unity";

exec($program, $output, $retval);

echo "<pre>".var_export($output, TRUE) . "</pre>";

echo "Return Value: $retval";

die;
?>

Incase anyone else runs into this problem, I was able to open Unity by changing line 5 to:

$program = "sudo -u yourUserName /Applications/Unity/Unity.app/Contents/MacOS/Unity";

where “yourUserName” is your preferred Unix user you’d like to open it with.

For some reason I couldn’t pass a password through PHP using echo PASS | sudo -u yourUserName -S despite people reporting that it would work.

This means you have to go into your sudoers file and change it so _www (or whatever user you use to run Apache) can use sudo commands without a needing to type a password.

I don’t really LIKE this solution, but it works on my development machine. I’ll post a more production friendly solution if I find it.