0

I have a similar question to this one which doesn't appear to have a happy resolution. It mentions using rotatelog.exe which is part of the Apache framework and not available to me.

I have inherited a Windows 2012 R2 web server from my predecessor, it is serving out PHP files via IIS 8.5. I recently tried to diagnose a problem with one of our sites only to discover the PHP error log was several GB in size (dating back to 2013).

Ideally I would like to rotate these logs on a daily or monthly basis.

How can I achieve this? PHP is 5.4, but a method for any version would be acceptable.

Burgi
  • 140
  • 13
  • Possible duplicate of [How Do I rotate the PHP Error Log?](http://serverfault.com/questions/169876/how-do-i-rotate-the-php-error-log) – 에이바 Mar 15 '17 at 14:18
  • @에이바 That references Apache not IIS. – Burgi Mar 15 '17 at 14:19
  • The PHP.ini file is still relevant to IIS. https://www.iis.net/learn/application-frameworks/scenario-build-a-php-website-on-iis/configuring-step-2-configure-php-settings – 에이바 Mar 15 '17 at 14:20
  • 1
    @에이바 As a SE rule of thumb, the fact that a question might have an identical answer does not necessarily mean the questions are duplicate... for example, here there might be a better answer for IIS specifically. Anyway, the sole answer on the one you linked also requires the use of an Apache binary, so unless you're suggesting the OP to download an additional binary... – Bob Mar 15 '17 at 14:30

1 Answers1

0

I solved this with a batch script and adding the script to the task scheduler to run daily. I am aware I could write this in PowerShell but I am not familiar enough with the shell to do this.

This is my batch script:

:: Batch script to rotate PHP logs
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS

SET logPath=c:\php\logs\
SET currentLog=PHP54_errors.log

FOR /F %%A IN ('WMIC OS GET LocalDateTime ^| FINDSTR \.') DO @SET B=%%A
MOVE %logPath%%currentLog% %logPath%%B:~0,4%-%B:~4,2%-%B:~6,2%.log
Burgi
  • 140
  • 13