Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug exec() problems?

Tags:

php

The exec command doesn't work on my server, it does not do anything, I've had safe_mode off, and verified that all the console commands are working, I've tried with absolute paths. I've checked the permissions on the applications and all the applications I need have execution permissions. I don't know what else to do, here are the rundown of the codes I've tried.

echo exec('/usr/bin/whoami');

echo exec('whoami');

exec('whoami 2>&1',$output,$return_val);
if($return_val !== 0) {
    echo 'Error<br>';
    print_r($output);   
}

exec('/usr/bin/whoami 2>&1',$output,$return_val);
if($return_val !== 0) {
    echo 'Error<br>';
    print_r($output);   
}

The last two codes display:

Error
Array ( )

I've contacted the server service and they can't help me, they don't know why the exec command isn't working.

like image 596
carcargi Avatar asked Aug 30 '12 14:08

carcargi


People also ask

How do I debug XDebug?

Press F5 to start the debugger. Click the new XDebug Helper extension and click the Debug option. Finally, refresh the page in the browser to let VSCode react and start the debugging process.

How do I know if XDebug is running?

Verify that Xdebug is properly running by checking again with phpinfo() or php -v as explained above. Note that 9003 is the default port. If this port is used by another service on your system, change it to an unused port. After adding these settings, restart your webserver again.


1 Answers

have a look at /etc/php.ini , there under:

; This directive allows you to disable certain functions for security reasons.
; It receives a comma-delimited list of function names. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
; http://www.php.net/manual/en/ini.sect.safe-mode.php#ini.disable-functions
disable_functions =

make sure that exec is not listed like this:

disable_functions=exec

If so, remove it and restart the apache.

For easy debugging I usually like to execute the php file manually (Can request more errors without setting it in the main ini). to do so add the header:

#!/usr/bin/php
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);

to the beginning of the file, give it permissions using chmod +x myscript.php and execute it ./myscript.php. It's very heedful especially on a busy server that write a lot to the log file.

EDIT

Sounds like a permissions issue. Create a bash script that does something simple as echo "helo world" and try to run it. Make sure you have permissions for the file and for the folder containing the file. you chould just do chmod 755 just for testing.

like image 189
Kuf Avatar answered Oct 10 '22 15:10

Kuf