Exec command does nothing in PHP


I have the following code:

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:

[email protected]:/home/rafael# find / -name php.ini -print
[email protected]:/home/rafael# find / -name php.ini-development -print
[email protected]:/home/rafael# find / -name php.ini-production -print
[email protected]:/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


and it has these parameters that may be of interest:

asked by rrg1459 17.08.2018 в 03:37

2 answers


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


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




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 :

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() :

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() :

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

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

answered by 17.08.2018 в 04:58