How to trace Apache segmentation fault?

Created:

2016-11-16 12:44:25 UTC

Modified:

2017-04-24 11:16:49 UTC

0

Was this article helpful?


Have more questions?

Submit a request

How to trace Apache segmentation fault?

Applicable to:

  • Plesk for Linux

Symptoms

  • Webpages return an HTTP error 500 in the main apache log usually it located in /var/log/httpd/error_log or /var/log/apache2/error_log .
  • "Segmentation fault" error can be found in Apache log files.

Cause

Some extension or interoperability with OS module causes a crash.

Resolution

  1. Find a partition having a free space enough to store several memory dumps. In this example, it will be root '/' partition.

  2. Modify Apache startup script:

    • For Debian-based systems add ulimit -c unlimited in /etc/init.d/apache2 , in do_start() section.

    • For RHEL-based OSes with init add DAEMON_COREFILE_LIMIT=unlimited to /etc/sysconfig/httpd file.
    • For systemd systems add LimitCORE=infinity in [Service] section of the unit file, e.g. for CentOS 7:

      [root@server ~]# cat /etc/systemd/system/multi-user.target.wants/httpd.service
      ...
      [Service]
      Type=notify
      ...
      LimitCORE=infinity
  3. Create a folder where core dumps will be stored:
    # mkdir -p /tmp/coredumps
    # chmod a+w /tmp/coredumps
  4. Modify /proc/sys/kernel/core_pattern to relative path

    # echo /tmp/coredumps/core-%e-%s-%u-%g-%p-%t > /proc/sys/kernel/core_pattern

    Note: if for some reason core_pattern can not be modified, it will be saved in a directory from where application started or CoreDumpDirectory location (see below).

  5. Add CoreDumpDirectory directive in httpd.conf and specify a location for a core dump file:

    [root@server ~]# grep "CoreDumpDirectory" /etc/httpd/conf/httpd.conf
    CoreDumpDirectory "/tmp/coredumps"
  6. Restart Apache service.

    Note: in order to test configuration you can send kill -SIGSEGV to Apache child and check whether dump file has been created.

  7. Open affected website/page in a browser and wait for 500 error.
  8. Ensure that core dump has been created in /tmp/coredumps/ directory.

    Note: that if abrtd daemon is running, it will prevent creation of core dump files.

  9. Remove ulimit -c unlimited from the init script and restart Apache.

  10. To analyse the core dump, pass the core dump filename on the gdb utility:

    gdb /usr/sbin/apache2 /tmp/coredumps/core-php-cgi-11-10007-1004-13087-1482920422
     /path/to/corefile
  11. Execute bt command at the gdb prompt to get backtrace and analyse output:

    (gdb) bt

Additional information

http://httpd.apache.org/dev/debugging.html

Have more questions? Submit a request
Please sign in to leave a comment.