Question

PHP Script Permission to Access Apache Logs on Ubuntu

  • Posted on July 12, 2013
  • msomersAsked by msomers

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?


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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