PHP Script Permission to Access Apache Logs on Ubuntu

  • Posted July 12, 2013

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?


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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. <br> <br>Try this: <br> <br>sudo cat /var/log/apache2/access.log | sudo php -f feed-subscribers.php

You have to use the visudo command as root to edit the file. Forgot to put that

In /etc/sudoers make sure you user has this line: <br>username ALL=(ALL:ALL) ALL

That worked, thank you! <br> <br>Just curious why it would work when switching into the root user versus just executing as sudo in my own user account?

Just to test things out… execute: <br><pre>sudo su</pre> <br>and then try your script, again. If that still doesn’t work, go to the folder where you saved <strong>feed-subscribers.php</strong> and execute: <br><pre>ls -l feed-subscribers.php</pre> <br>and copy and paste (onto this thread) the output.