Report this

What is the reason for this report?

PHP Script Permission to Access Apache Logs on Ubuntu

Posted on July 12, 2013

I’m trying to run a PHP Script that parses my Ubuntu Apache Logs for RSS Subscribers (https://gist.github.com/marcoarment/5968198) 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?



This textbox defaults to using Markdown to format your 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.

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?

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

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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.