如何在PHP中获取Apache和MySQL日志

如何在PHP中获取Apache和MySQL日志,php,mysql,apache,ubuntu,Php,Mysql,Apache,Ubuntu,我希望在我的PHP脚本中获得Apache和MySQL日志,如: echo(file_get_contents('/var/log/apache2/error.log')); echo(file_get_contents('/var/log/mysql/error.log')); 在那之后,我明白了: file_put_contents('/var/log/mysql/error.log',''); 但这些都不管用 可能存在访问权限冲突?您需要将用户名添加到组中 sudo usermod-aG

我希望在我的PHP脚本中获得Apache和MySQL日志,如:

echo(file_get_contents('/var/log/apache2/error.log'));
echo(file_get_contents('/var/log/mysql/error.log'));
在那之后,我明白了:

file_put_contents('/var/log/mysql/error.log','');
但这些都不管用


可能存在访问权限冲突?

您需要将用户名添加到组中 sudo usermod-aG adm YourUserName


谢谢你的工作!sudo usermod-aG adm www数据之后
<?php   
    echo shell_exec('tail -f /var/log/apache2/error.log');

?>

or

<?php
$op = array();
exec('tail -f /var/log/apache2/error.log', $op, $stat);
print_r($op);
?>