1

I am running a website on OSX server, that needs to execute pdftotext, which is installed in /usr/local/bin. However, there seems to be an issue with the command not being in the Apache path.

I first confirmed that I can execute shell scripts. <?php shell_exec('whoami'); ?> returns _www.

However, when I run the following :

 $cmd = 'has pdftotext 2>&- || echo 1';
 $out = shell_exec($cmd);
 echo $out;

it returns "1" meaning it cannot access the command.

The same command run from terminal returns nothing (I can access the program without any issue).

When I run shell_exec('env'."2>&1") /usr/local/bin is indeed not in the path. Where do I set it for Apache2 on OSX Mountain Lion Server ?

UPDATE

See answer below

1 Answer 1

1

I found the answer as to how to modify the Apache PATH here: https://gist.github.com/thebigdog/5208619

I needed to modify /System/Library/LaunchDaemons/org.apache.httpd.plist, adding

<key>PATH</key>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>

to the existing <key>EnvironmentVariables</key> definition. So in the end it looked like this:

<key>EnvironmentVariables</key>
<dict>
    <key>PATH</key>
    <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
    <key>SERVER_INSTALL_PATH_PREFIX</key>
    <string>/Applications/Server.app/Contents/ServerRoot</string>
    <key>XPC_SERVICES_UNAVAILABLE</key>
    <string>1</string>
</dict>

Once I restarted the Apache server, the path was added and the shell command was executed properly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.