PHP Script Permission to Access Apache Logs on Ubuntu

July 12, 2013 4.9k views
I'm trying to run a PHP Script that parses my Ubuntu Apache Logs for RSS Subscribers ( by executing: php -f feed-subscribers.php < /var/log/apache2/access.log The problem is that even if I run it as sudo, I get an access denied error. I've been able to execute bash and python scripts with sudo that worked fine accessing the apache logs. Can anyone give some guidance on how to adjust my set up to work properly?
5 Answers
Just to test things out... execute:
sudo su

and then try your script, again. If that still doesn't work, go to the folder where you saved feed-subscribers.php and execute:
ls -l feed-subscribers.php

and copy and paste (onto this thread) the output.
That worked, thank you!

Just curious why it would work when switching into the root user versus just executing as sudo in my own user account?
In /etc/sudoers make sure you user has this line:
username ALL=(ALL:ALL) ALL
You have to use the visudo command as root to edit the file. Forgot to put that
Prefixing it with sudo won't work because you can't access /var/log/apache2/access.log, sudo only affects the "php -f feed-subscribers.php" part.

Try this:

sudo cat /var/log/apache2/access.log | sudo php -f feed-subscribers.php
Have another answer? Share your knowledge.