简体   繁体   中英

PHP shell_exec will not run ls

I am running the following php script:

<?php

ini_set('display_errors', 'On');
error_reporting(E_ALL);

date_default_timezone_set('UTC');

echo nl2br("Before\n\n");

$out = shell_exec("ls -lart");
echo "<pre>$out</pre>";

echo nl2br("After\n\n");


?>

I cannot get shell_exec or exec to work at all. The script above produces:

Before
After

but nothing in between.

I think shell_exec function is disabled in your php.ini . You can check it by

if(function_exists('shell_exec')) {
    echo "shell_exec is enabled";
} else {
    echo "shell_exec is disabled";
}

Open your php.ini and navigate to section disable_functions

If shell_exec is listed under there , remove it.

Then restart apache / php handler.

Also If Safe Mode is enabled this function will not be available. You need to disable it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM