Advice for Debugging Apache with PHP Segmentation Faults
Solution 1:
I've seen this before.. apart from getting your PHP app developers to check their code, and making sure you have up-to-date versions (from your distribution) of PHP and apache, there isn't much you can do.
If you're running an Op-Code cacher (eaccelerator, APC or XCache), you could try turning them off, they're known to cause the odd segfault.
In the past, we've had to deploy some impressively hackish solutions to a segfaulting system, for short-term fixes, of course. For example, this cronjob worked well:
# Restart apache when a segfault is found in the most recent line of errorlog
#*/5 * * * * tail -n1 /var/log/apache2/error.log | grep 'Segmentation fault' && /etc/init.d/apache2 restart
Or you could try something a bit more clever:
#*/5 * * * * /usr/bin/wget http://www.my-site.com/ -T10 -O 2> /dev/null - | grep "Hosted by" > /dev/null || /usr/local/bin/brutally_restart_apache.sh
Where brutally_restart is:
#!/bin/sh
/usr/sbin/apache2ctl stop
sleep 6
killall -9 apache2
sleep 4
/usr/sbin/apache2ctl start