Search code examples
phpmacososx-yosemite

How to use shell_exec xampp php in a Mac


I just cant figure it out how can execute shell commands on php. it must suppose to echo the parameters of mogrify but it always return false. How could i do it on a macbook pro yosemite? i already tried editing all users permissions to read/write/execute but still no luck.. already tried researching the web about this and cant get the answer.

my code is:

<?php
echo shell_exec("/opt/ImageMagick/bin/mogrify");
?>

Solution

  • OK for all of you to solve this kind of problem that any terminal application don't run on mac and returns null in any kind of calling terminal apps like shell_exec, exec, system etc. this is the one of a kind that took me 24 hours to know.. it's about the working dir.

    // The Code that took me 24 Hours to Discover.
    exec('unset DYLD_LIBRARY_PATH ;');
    putenv('DYLD_LIBRARY_PATH');
    putenv('DYLD_LIBRARY_PATH=/usr/bin');
    $voila = shell_exec("anything you want to execute!");
    var_dump($voila);
    

    with that work around your problem will be fixed.