Question

I am trying to increase the admin functionality of a php project I working on. As of now the project will log all of its errors to the syslog. I am trying to give the admin page the ability to read the syslog for these errors. in the terminal I can type:

cat /var/log/syslog | grep projectName

However ever if I try to run this command with:

$output=shell_exec('cat /var/log/syslog | grep projectName');

or with :

$output=`cat /var/log/syslog | grep projectName`;

$output always comes up as empty. Is there a way I can do this? Is this even the best way (IE does php have a native way to read the syslog)?

EDIT: it seems that the issue is a permissions one. I could give www-data permission to access syslog, but for some reason that doesn't seem like a good idea to me. Is there no native way to read the log?

Was it helpful?

Solution

I ended up creating a completely separate log file. This took care of all the permission issues

OTHER TIPS

Can't you open /var/log/syslog your self in php instead of doing a shell command?

Ever hear of sudo? It may be your best choice if you concerned with security. But I think going the sudo route is too complicated, just give a read premission to web user, it's not a write a read premission. In order for this to be a security concert there must be a way for someone else to write a php script that reads the syslog file. If you are the only one who can upload php scripts to your server, then you should not worry about that at all. For shared hosting this is a problem, of cause as anyone will now be able to read server's syslog.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top