Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell Command in PHP file : Display the content of a file in a webpage

Tags:

shell

php

ubuntu

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>";
?>
like image 731
xXxrk04 Avatar asked Oct 20 '25 13:10

xXxrk04


1 Answers

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>";
?>
like image 159
DJ' Avatar answered Oct 22 '25 04:10

DJ'



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!