How to get a core dump from apache when segfaulting

28,456

Solution 1

My answer is this:

  1. Set up the directive as follow

    CoreDumpDirectory /tmp/mycoredump

  2. Create the directory:

    mkdir -p /tmp/mycoredump

  3. Assign ownership to the directory www-data or httpd

    chown -R www-data:www-data /tmp/mycoredump

  4. Set permissions to:

    chmod 777 /tmp/mycoredump

  5. Restart Apache:

    service apache2 restart

Solution 2

Note that if you have PrivateTmp=true set in your /usr/lib/systemd/system/apache2.service (or whatever it's called on your system), meaning Apache actually looks for /tmp inside something like /tmp/systemd-private-c27fc5b152d546159d675e170641529b-apache2.service-IcEt0m/, Apache won't be able to write to that dir and you won't get cores dumped at all (due to the systemd tmp directory having 700 root-only perms).

The solution is to either set PrivateTmp=false or modify the permission of the systemd tmp directory after the server starts.

I wasted hours on this to only just now finally realize what the problem was.

Share:
28,456

Related videos on Youtube

chrismcb
Author by

chrismcb

Web developer in Glasgow

Updated on September 18, 2022

Comments

  • chrismcb
    chrismcb almost 2 years

    I've followed instructions from many locations online on how to get a core dump from apache when it is producing a segfault, but it still refuses to generate the dump.

    I have:

    1. Added the CoreDumpDirectory directive into the httpd.conf file and set it to /tmp
    2. Executed ulimit -c unlimited
    3. Provided the pattern for dumps using echo '/tmp/core-%e.%p' > /proc/sys/kernel/core_pattern
    4. Also ran echo 0 > /proc/sys/kernel/core_uses_pid

    Httpd has been restarted, but still no dumps created.

    I'm running CentOS 5.8 x64 with httpd-2.2.3-65.el5.centos.3 and php-5.3.20-13.el5.art

    Any help would be much appreciated!

    • chrismcb
      chrismcb over 11 years
      I've set it to /tmp which is publicly writable, but I'll try somewhere else and give it ownership to apache
    • chrismcb
      chrismcb over 11 years
      Thanks - that did produce a dump, however not in the place I set it! I set the CoreDumpDirectory to /tmp/dumps and it dumped to /tmp... now on with debugging
    • Valentin Bajrami
      Valentin Bajrami over 11 years
      Glad you figured it out!
  • chrismcb
    chrismcb over 11 years
    Yes, I did just about that, but it ended up dumping into /tmp anyway!
  • sendmoreinfo
    sendmoreinfo over 11 years
    It's never a good idea to chmod 777 anything
  • avgvstvs
    avgvstvs almost 9 years
    @sendmoreinfo But what if your use case is making something fully modifiable and executable to the outside world? ;-)
  • sendmoreinfo
    sendmoreinfo almost 9 years
    You are allowed to shoot yourself in the foot, just don't preach this.
  • 3ventic
    3ventic about 4 years
    Oh you have no idea how many hours I've wasted on this. Thanks for posting your answer!
  • Cerin
    Cerin over 3 years
    If I run these, it kills Apache and makes it unable to start... CoreDumpDirectory does not appear to be a valid Apache directive.