Title: Can&#039;t Write Error Logs
Last modified: August 22, 2016

---

# Can't Write Error Logs

 *  [curtisbryant](https://wordpress.org/support/users/curtisbryant/)
 * (@curtisbryant)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/cant-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)

 *  Thread Starter [curtisbryant](https://wordpress.org/support/users/curtisbryant/)
 * (@curtisbryant)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/cant-write-error-logs/#post-5276366)
 * 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.

## Tags

 * [file](https://wordpress.org/support/topic-tag/file/)
 * [iis](https://wordpress.org/support/topic-tag/iis/)
 * [IUSR](https://wordpress.org/support/topic-tag/iusr/)
 * [log](https://wordpress.org/support/topic-tag/log/)
 * [permissions](https://wordpress.org/support/topic-tag/permissions/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [curtisbryant](https://wordpress.org/support/users/curtisbryant/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/cant-write-error-logs/#post-5276366)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
