Thursday, June 26, 2014

HOW TO FIGURE OUT WHAT IS CAUSING AN APACHE SEGMENTATION FAULT

SkyHi @ Thursday, June 26, 2014

Having an apache segmentation fault on your server can drive you crazy trying to solve it… So, I’m gonna explain you how I figured out what was causing the last apache segfault I had.
My server was running under Debian Squeeze, with Apache 2.2 and PHP 5.3, and I got randomly segmentation faults:
I supposed the problem was on some php extension, so I deactivated some of them…but the problem was still there :(
After spending a lot of time looking for what was causing it, I decided to debug apache with gdb. I installed it through backports because I needed an upper version than gdb 7.0 (7.0.1-2 is the current version on squeeze stable repository) otherwise I got this: “warning: The current binary is a PIE (Position Independent Executable), which GDB does NOT currently support. Most debugger features will fail if used in this session.” when I was trying to debug apache:
Well, I had the debugger installed, but I also needed the php and apache debug symbols:
Once I had installed all I needed, I configured apache to create a core dump file every time it had a segfault by adding in /etc/apache2/httpd.conf the following line:
Previously, I had created the /tmp/apache-coredumps directory
By default, my system core file size was 0, so I had to change it through ulimit:
I restarted apache, and I only had to wait for the next Segmentation fault… and I didn’t have to wait too much …
Then, as the message said, I had a core file in /tmp/apache-coredumps, and I was closer to finding out what was causing segfaults :)
Therefore, it was time to use gdb:
I had a problem with php as I thought, and I was able to find more information about it. And after Googling for a few minutes, I found there is a bug with the PHP and APC version that I was using! (more info here)
After that, I could solve the problem and until now I haven’t got more segfaults on this server :)
Using gdb will not solve your segmentation faults, but at least, you will be able to figure out what’s causing it, and you’ll get more info to solve it.


REFERENCES
http://sysadmin.carlusgg.com/?p=197