0

I'm not able to print kubectl output on chrome web browsers using php shell_exec() function.

i'm trying to display output of shell_exec() on my web browser. The php code is working fine when i run on terminal but as i run on chrome then only output2 is printing. But i need to print output1 as well.

Can any one help to resolve this issue? Running my status.php with below on CentOS Linux release 7.9.2009 (Core)

cmd: php status.php

My status.php page:



<?php

$ns = "bind";
echo $ns;

$cmd = "kubectl --kubeconfig /var/www/html/config get pod -n $ns";

$cmd2= "ls -lrth";
echo "<pre>";
$output1 = shell_exec($cmd);

$output2 = shell_exec($cmd2);

echo $output1;         // Printing this output value on terminal but not printing on web browser

echo $output2;
echo "</pre>";          // Printing this output2 value on terminal as well web browser

echo "after shell_exce funtion"
?>

--

My OS is CentOS Linux release 7.9.2009 (Core) cat /etc/redhat-release

my php version:

PHP 5.4.16 (cli) (built: Apr 1 2020 04:07:17) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

i'm trying to display output of shell_exec() on my web browser. code is working fine when i run on terminal but as i run on chrome then only output2 is printing. But i need to print output1 as well.

  • PHP probably isn't running as your same user so I would guess `/home/ravindra/.kube/config ` can't be accessed by webserver. You should find the error logs coming out of your web server - those are going to be very important for web development – erik258 Feb 15 '23 at 16:30
  • What have you tried to resolve the problem? Where are you stuck? Also, PHP 5.4.16 is **horribly** outdated – Nico Haase Feb 15 '23 at 16:30
  • Maybe https://stackoverflow.com/questions/15086572/php-how-to-get-shell-errors-echoed-out-to-screen helps? – Nico Haase Feb 15 '23 at 16:31

0 Answers0