0

File structure setup like so,

mainDirectory
-app
--logs
---errors.log
-file.php

Inside of file.php I have,

ini_set("log_errors", 1);
ini_set("error_log", "logs/errors.log");

I then try to output results like this later,

error_log( print_r($response, TRUE) );

However it just dumps to console. I then tried various checks like

if( file_exists( "logs/errors.log" ) ) {
    echo 'yup';
}
else {
    echo 'nope';
}

And each time is "nope"

Am I missing something obvious here?

Thank you.

5
  • does the php service have permission to write to logs directory? Commented Aug 22, 2017 at 16:59
  • Hm unsure, do you mean is file writeable? Commented Aug 22, 2017 at 17:04
  • take a look here : stackoverflow.com/questions/15530039/… Commented Aug 22, 2017 at 17:05
  • if logs cannot be written to then no error log will be created. Use ls -dl logs from app directory to check. Commented Aug 22, 2017 at 17:06
  • drwxr-xr-x 3 thatryan staff 102 Aug 15 09:02 log/ that is what gets returned Commented Aug 22, 2017 at 17:11

1 Answer 1

1

My guess is that you're running into a permissions problem. I'm running Apache on OSX Sierra and my log files are stored in /var/log. If I try to the line below, I get a permission denied error.

file_put_contents('/var/log/apache2/errors2.log', 'Hello world');

You might consider choosing a location for your error_log that you are certain Apache has permission to write to like /tmp.

ini_set("error_log", "/tmp/errors.log");

Try using file_put_contents to test the permissions of the directory before using ini_set which can be a bit terse.

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

Comments

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.