Support » Fixing WordPress » Can't Write Error Logs

  • I need to troubleshoot my WordPress custom plugin but can’t write error logs. When I try (using fopen, fwrite, and fclose), this error arises: “failed to open stream: Permission denied….”

    It’s WordPress 3.5 on IIS (Windows Server 2008).

    Other forums I’ve checked always say to check the file permissions, so I ran the PHP get_current_user() function. It says the file owner is IUSR. This user does not have write privileges. I tried temporarily giving this user the write privilege and using the PHP error_log function, but the result was the same–permission still denied.

    What about file permissions in PHP or IIS am I missing?

Viewing 1 replies (of 1 total)
  • It turns out that running the following PHP page does write and save to the file:

    <?php
      function log( $msgs ) {
    
        $filepath = "log.txt";
        $lineBreaks = PHP_EOL . PHP_EOL;
    
        $file = fopen( $filepath, "c" );
        foreach( $msgs as $msg ) {
            fwrite( $file, $msg . $lineBreaks );
        }
        fclose( $file );
    
    }
    
    log( array( 'Hi there!', 'This is a message.' ) );
    ?>

    But when I paste this function into my WordPress plugin, it says permission denied. Why?

Viewing 1 replies (of 1 total)
  • The topic ‘Can't Write Error Logs’ is closed to new replies.