1

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?

2
  • 1
    Don't take this as stating the obvious, but instead of using the root owned syslog that also includes other log data from the rest of the system, why not get the project its own log file, owned by it, and without the extra noise? Commented Nov 7, 2010 at 13:07
  • ^ that is exactly what I ended up doing. Commented Nov 24, 2010 at 22:17

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Any reason for the downvote? This was how I got past the issue.
1

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

6 Comments

Just tried it. Now I know why it didn't work before: Warning: fopen(/var/log/syslog): failed to open stream: Permission denied
You can chmod syslog so that www user can read it. Otherwise, even doing command line will not work.
I could easily do that, but would there be any security concerns in doing so?
More secure that running apache as root. :)
I think I am going to make a cron job that copies the syslog to a safe location and then have my php site parse that.
|
-2

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.

4 Comments

I don't think sudo is his solution. You can't sudo and enter password in php. Where is he going to store root password? In PHP? :)
even if I did store the sudo password in the php file, www-data isn't in the admin group, and I have no intention of putting it there
While I agree that sudo might not be the way to go, it's not because you'd have to enter the password. Wouldn't you just setup sudoers and then not require a password?
You don't have to enter password in sudo, there is a specific option for that, basically you can configure it in /etc/sudoers to allow specific user (www or whatever user apache running under) to execute one specific script (full path to script) while assuming the identify of root (just for this one time) and without a password. You can lookup all the sudo options online, one of them is 'nopasswd'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.