Extremist Developer

RSS
Jan 6

Debugging Apache2 / PHP on Ubuntu

  Yesterday i came across a little issue, after installing the Memcache extension (through the package manager on Ubuntu 10.10), my Apache was segfaulting. Since i just finished the setup of this box, they was too many possible culprit to just go ahead (and come on sunday) and just disable/reinstall the extension. So i decided to run Apache through gdb. 

It’s not as easy as it sounds, if you just go with you instincts and run (we’ll assume from now on that you are root):

gdb apache2

This will start gdb correctly, and if in gdb you type run -X , you will get this little message :

apache2: bad user name ${APACHE_RUN_USER}

The trick there is before running gdb (still as root) you will need to export those envvars (from /etc/apache2/envvars ) :

export APACHE_RUN_USER=www-data

export APACHE_RUN_GROUP=www-data

export APACHE_PID_FILE=/var/run/apache2.pid

export LANG=C

export LANG

Now if you run gdb again and type run -X , everything will start correctly and you’ll be able to see what is going on under the hood.