Sunday, August 21, 2016

Error using PHP exec in MAMP in OSX (El Capitan)

Problem:


  • I ran into an error trying to execute a system command in PHP 5.4.4 using exec, shell_exec, or system in MAMP. 
  • Example error: “image not found for libcaffe”.
  • This command executed fine from Terminal, but would not work within MAMP.  
  • <?php
       $cmd = "some command here";   
       shell_exec($cmd);
    ?>

Diagnosis:

  • The $PATH did not seem to be correct (compared to what I have in ~/.bash_profile.), so MAMP must not be setting it up correctly
  • <?php shell_exec("echo $PATH"); ?>
    

Solution:
  • Stop MAMP
  • Copy unused environment variables file
  • cp /Applications/MAMP/Library/bin/envvars_ /Applications/MAMP/Library/bin/envvars
    
  • Edit environment variables file
  • vi /Applications/MAMP/Library/bin/envvars
    
  • Add the following line: 
  • ~/.bash_profile
    
  • Start MAMP


3 comments:

  1. I like this kind of solution to the problem. It is very convenient and accessible, without another word. The problem, then the diagnosis and solution. The golden mean to solve any problem. I once was a trainee in a professional php team. They taught me a lot. I am very grateful to them for that. Now I am a professional php developer, thanks to this fateful internships.

    ReplyDelete
  2. Solving the problem in such a way is a good solution. It's an awesome piece of writing for all the web viewers;
    they will obtain advantage from it I am sure.

    ReplyDelete
  3. Hello, I do believe your site may be having internet browser
    compatibility problems. Whenever I take a look at your blog in Safari,
    it looks fine however, if opening in Internet Explorer,
    it has some overlapping issues.I merely wanted to give you a quick heads up! Besides that, excellent website!

    ReplyDelete