Debug segmentation faults in Apache from mod_wsgi

In this guide we show how to get information from apache segmentation faults that come from python’s mod_wsgi.

Segmentation faults in apache from mod_wsgi don’t hint at all what causes them, so we cannot know how to solve them:

AH00052: child pid 9972 exit signal Segmentation fault (11)

In this guide we show how to get information from them. It is based on the official mod_wsgi guide, but updated, concise and tested with Debian. We assume you know how to configure apache with mod_wsgi, and that you have an existing configuration of your server.

The first thing to do is put mod_wsgi into embedded mode, because we want it to be in the same apache process, and daemon mode is not. This is how we do it: Remove WSGIDaemonProcess, WSGIProcessGroup and WSGIApplicationGroup from your apache’s virtualhost to be in embedded mode. And only if you were using python-home="/path/to/env" in WSGIDaemonProcess, add WSGIPythonHome /path/to/pyvenv in your apache2.conf.

Install gdb (in Debian just apt install gdb).

Run apache with gdb: sudo gdb /usr/sbin/apache. Debian won’t allow you to run gdb correctly as it uses some environment variables in the configuration file; run gdb the following way:

source /etc/apache2/envvars
sudo -E gdb /usr/sbin/apache

In gdb, write run -X and press enter.

Access the web with your browser that generates the error, and see how in your terminal shows the faulty line.



One thought on “Debug segmentation faults in Apache from mod_wsgi

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.