I am trying to execute a command with shell_exec but this command does not work, other commands work
<?php
$output = shell_exec("tail /var/log/syslog");
echo "<pre>$output</pre>";
?>
I am trying to execute a command with shell_exec but this command does not work, other commands work
<?php
$output = shell_exec("tail /var/log/syslog");
echo "<pre>$output</pre>";
?>
Please execute and post the error from your PHP error.log
file.
When we code in PHP, we always run a tail
on the PHP error.log
file so we can see errors as the occur.
[Fri Sep 20 16:29:05.960464 2019] [mpm_prefork:notice] [pid 1090] AH00163: Apache/2.4.29 (Ubuntu) configured -- resuming normal operations
[Fri Sep 20 16:29:05.960506 2019] [core:notice] [pid 1090] AH00094: Command line: '/usr/sbin/apache2'
tail: cannot open '/var/log/syslog' for reading: Permission denied
So...?
So, it pretty obvious that since your core PHP process cannot read /var/log/syslog
; hence the basic problem is not shell_exec
, the problem is that this file is not readable by your LAMP
server process.
Please execute these commands:
ls -l /var/log/syslog
and also
ps aux | grep -i apache | tail -10
... and cut-and-paste the results (using our code tags) into your reply.