How can I debug exec() problems?

php exec
php exec not working
php popen
php exec timeout
running shell command in php with real time output
php exec stderr
php shell_exec not working
shell_exec(): unable to execute

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>';

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

The last two codes display:

Array ( )

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

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.
disable_functions =

make sure that exec is not listed like this:


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:

ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);

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.


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.

exec - Manual, If you do not want the function to append elements, call unset() on the array before On Windows exec() will first start cmd.exe to launch the command. On Windows-Apache-PHP servers there is a problem with using the exec command​  For debugging always wrap your exec/shell_exec function in var_dump(). error_reporting(-1); should be on, as should be display_errors, as last resort even set_error_handler("var_dump"); - if only to see if PHP itself didn't invoke execvp or else. Use 2>&1 (merge the shells STDERR to STDOUT stream) to see why an invocation fails.

Since you are dropping out of the PHP context into the native shell, you are going to have a lot of issues debugging.

The best and most foolproof I have used in the past is writing the output of the script to a log file and tailing it during PHP execution.

shell_exec("filename > ~/debug.log 2>&1");

Then in a separate shell:

tail -200f ~/debug.log

When you execute your PHP script, your errors and output from your shell call will display in your debug.log file.

How to debug a bash script?, Additional with bash 4.1 or later: If you want to write the debug output to a separate file, add this to your script: exec 5> debug_output.txt BASH_XTRACEFD​="5". Because we see a problem in the output, we will start debugging by looking at the preceding code that sets the output in the debugger. Click the Restart button in the Debug Toolbar (Ctrl + Shift + F5). The app pauses at the breakpoint that you set.

You can retreive the outputs and return code of the exec commands, thoses might contains informations that would explain the problem...

exec('my command', $output, $return);

Debugging with GDB, When you run a program under GDB, you must first generate debugging information If in doubt, recompile with `-g' alone, and if this fixes the problem, please or by using the file or exec-file command (see section Commands to specify files). (gdb) info threads 3 process 35 thread 27 0x34e5 in sigpause () 2 process 35  Press the drop-down arrow on the green arrow button in the Transact-SQL editor toolbar and select Execute with Debugger to execute the query with debugging on. Alternately, you can start debugging from SQL Server Object Explorer. Right-click the AddProduct stored procedure (located under Local-> TradeDev database -> Programmability-> Stored Procedures). Select Debug Procedure. If the object requires parameters, the Debug Procedure dialog box appears, with a table containing a row for each

How to solve Exec binding problems - Bindings, How to Debug. Some easy steps: If the command or the called script calls sudo , make sure openhab is a member of sudoers and  At this point, you may want to execute the current statement and then inspect the changed values. You can use several step commands to execute code in the debugger. If the marked code is a method call, you can step into it by pressing F11. You can also step over the line of code by pressing F10.

please remove the need to type -exec in debug console to execute a , please remove the need to type -exec in debug console to execute a native debugger command #2520. Closed. DanPartelly opened this issue  You can see these options by clicking Debug as shown in the screenshot below: Step Over (F 10) Step Over simply moves the cursor to the next line of executable script. For instance, if the debugger Step Into (F 11) This is one of the most important and useful debugging features. Step Into lets

Debugging with GDB: Starting, When you issue the run command, your program begins to execute GDB starts your program with a shell command of the form exec wrapper program . Run to a breakpoint in code To set a simple breakpoint in your code, click the far left margin next to the line of code where you want to suspend execution. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert Breakpoint.

CCNA Routing and Switching 200-125 Official Cert Guide Library, The debug EXEC command gives the network engineer a way to ask IOS to with that monitoring process continuing over time, so that IOS can issue log  WP_DEBUG is a PHP constant (a permanent global variable) that can be used to trigger the “debug” mode throughout WordPress. It is assumed to be false by default and is usually set to true in the wp-config.php file on development copies of WordPress.