Exec command does nothing in PHP

1

I have the following code:

<?php
echo "Hola mundo.";
exec ("uname -a");
exec ("echo uname -a");
?>

the exec command does nothing on the two lines.

I'm newbie in php and I'm stuck.

SO Lubuntu 18.04

xampp 5.6.30

PHP Version 5.6.23 ( According to PHPInfo )

If you suggest that I check the php.ini, you can tell me which of the php.ini I have is what I have to see:

root@Lubuntu18:/home/rafael# find / -name php.ini -print
/etc/php/7.2/apache2/php.ini
/etc/php/7.2/cli/php.ini
/etc/php/5.6/apache2/php.ini
/etc/php/5.6/cli/php.ini
/opt/lampp/etc/php.ini
root@Lubuntu18:/home/rafael# find / -name php.ini-development -print
/usr/lib/php/7.2/php.ini-development
/usr/lib/php/5.6/php.ini-development
root@Lubuntu18:/home/rafael# find / -name php.ini-production -print
/usr/lib/php/7.2/php.ini-production
/usr/lib/php/5.6/php.ini-production
root@Lubuntu18:/home/rafael# 

If you suggest that you remove exec from disable_functions , disable_options only has this pcntl_exec option, I have removed and put and nothing. Nowhere does exec come out.

Any ideas that complement what I have tried or something different ???

Update :

Investigating a little more I confirmed that the php.ini that reads is the

/opt/lampp/etc/php.ini

and it has these parameters that may be of interest:

disable_functions=
safe_mode=Off
    
asked by rrg1459 17.08.2018 в 03:37
source

2 answers

1

The exec() function returns the last line returned by the execution as a string:

  

string exec (string $ command [ array & $ output [ int & $ return_var]])

     

Parameters

     

command : The command that will be executed.

     

output : If the argument output is present, then the specified array will be filled with each line of the output of the command [...]

     

return_var : If the return_var argument is present together with the output argument, then the return status of the executed command will be written to this variable.

     

Return values

     

The last line of the command results. If you need to execute a command and have all the data from the command passed directly back without any interference, use the function passthru() .

     

To get the output of the executed command, be sure to define and use the output parameter.

By not sending anything to the browser, you have to explicitly use some function that sends the information, such as echo :

<?php
echo "Hola mundo.";
echo exec("uname -a");
echo exec("echo uname -a");

An alternative way that shows all the output (and not just the last line) directly in the browser would be by using passthru() :

<?php
echo "Hola mundo.";
passthru("uname -a");
passthru("echo uname -a");

The problem is that you do not control the output in order to convert it to HTML safely.

If you want to store the full result of the output so that you can treat it as HTML using htmlspecialchars() , then you should use shell_exec() :

<?php
echo "Hola mundo.";
echo '<pre>', htmlspecialchars(shell_exec("uname -a")), '</pre>', PHP_EOL;
echo '<pre>', htmlspecialchars(shell_exec("echo uname -a")), '</pre>', PHP_EOL;
    
answered by 17.08.2018 / 13:48
source
1

the php.ini that you should review in your case is

/etc/php/5.6/apache2/php.ini
    
answered by 17.08.2018 в 04:58