I need some help, how can I execute a shell command in a php file? on how to display the content of a file in a webpage.
I tested this script, it works
<?php
$output = shell_exec('ls /var/www/vhosts/resame');
echo "<pre>$output</pre>";
?>
but this script, did not display anything.
<?php
$output = shell_exec('cat /var/log/mail.log');
echo "<pre>$output</pre>";
?>
Run this command first (based on your apache user)
CHMOD 777 /var/log/mail.log
If apache user is nobody
CHOWN nobody /var/log/mail.log
If apache user is www-data
CHOWN www-data /var/log/mail.log
Then use the following to display data on the web page.
<?php
$output = shell_exec('cat /var/log/mail.log 2>&1');
echo "<pre>$output</pre>";
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With