1
votes

I have a php file which needs to be executed in CLI from my Php application which runs on CodeIgniter framework. I tried the exec and shell_exec command and it seems to not start the process. Please find the code below which I try to execute.

$phpPath = exec('which php');
$cmd = $phpPath.' '.dirname(__DIR__).'/API/notification/NotificationServer.php';
echo "<pre>".shell_exec($cmd)."</pre>";

When I try running the above in Terminal it executes fine. I need to automatically trigger this once the user has a session set.

The path/$cmd variable prints

when I print the variable $cmd i get the below output, and the below when given in terminal works fine.

/usr/bin/php /Users/lalithb/Desktop/Android/AndroidWS/API/notification/NotificationServer.php

the above command works fine in the Terminal. When i try to exec/shell_exec it, it is not working.

APACHE_ERROR LOGS ARE :

sh: line 1:  2437 Trace/BPT trap: 5       /usr/bin/php
sh: line 1: /Users/lalithb/Desktop/Android/AndroidWS/API/notification/NotificationServer.php: Permission denied

Can someone help me out in running this above code in CLI ?

1
So, if it doesn't start the process, what does happen? Any errors, warnings or notices? Make sure you've cranked error_reporting all the way up. Perhaps you need to specify the full and complete path both to the php binary and to the script you're trying to invoke? - Charles
I have provided the full complete path of the php binary, I am not able to set permissions. I dont have sudo access to the server which I'm using, Is there a way to run the code above ? - Lalith B
@Charles Thanks, I found the solution. - Lalith B

1 Answers

0
votes

I solved the problem, Guess there would be someone else like me trying to access the restricted folders. I found the solution here

http://ubuntuforums.org/showthread.php?t=1302259

exec('chmod +x'.dirname(__DIR__).'/API/notification/NotificationServer.php);

The above worked the magic.