[CentOS] How to rotate PHP error log - since it belongs to apache

Andre Goree

andre at drenet.info
Tue Jun 5 16:57:06 UTC 2012

On 06/05/2012 10:15 AM, Alexander Farber wrote:
> Hello Luigi and others,
> On Tue, Jun 5, 2012 at 4:04 PM, Luigi Rosa <lists at luigirosa.com> wrote:
>> Alexander Farber said the following on 05/06/12 15:57:
>>> So my question is for how to rotate it (esp. since it should be owned by
>>> "apache" user) - what do you guys use?
>> the standard logrotate config /etc/logrotate.d/httpd or a modified copy of it
>> since the rotation moves the old log and then reloads Apache, you don't have
>> to worry about the ownership issue
> yes, I'm aware of that file and have modified
> the docs path in it because I have several vhosts too...
> Here is my current /etc/logrotate.d/httpd file:
> /var/log/httpd/my_vhost_1/*log {
>     missingok
>     notifempty
>     sharedscripts
>     delaycompress
>     postrotate
>         /sbin/service httpd reload > /dev/null 2>/dev/null || true
>     endscript
> }
> But my problem is I don't know how to do it best -
> i.e. where to put the PHP log file
> /var/log/php/php_errors.log
> in the directives above and also how to rotate
> the logs for all vhosts I have (I currently rotate just
> for one - the "my_vhost_1" as you can see above)
> Regards
> Alex
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> http://lists.centos.org/mailman/listinfo/centos

Create a different file under /etc/logrotate.d (perhaps name it
"phplog", doesn't really mater though) and add the appropriate
configuration options.  I used this website to help me with the
necessary options (though the man page is more than sufficient as well):

Here is a custom logrotate conf I created for my catalina logs:

[root at 390405-web1 images]# cat /etc/logrotate.d/tomcat
/opt/apache-tomcat-5.5.34/logs/catalina.out {

If you were wanting to rotate according to the size of the file (perhaps
512MB, whatever works for you though) owned by apache, you might create
a file under /etc/logrotate.d/ containing something like the following:

/var/log/php/php_errors.log {
 size 512MB
 create 644 apache apache

There's all kinds of other options you can add as well.  Read the
article I linked earlier and/or the man page, it's really pretty
trivial.  Good luck :)

Andre Goree
andre at drenet.info

More information about the CentOS mailing list