5

Is there any way to get the Apache web server to display it's current running config, from memory, i.e. not by parsing the files in the config directories?

I've just managed to accidentally over-write the vhost config on a server (yes, I know, should have had a backup!), and while I can reconstruct it fairly easily (very new server, so simple config and hence no backup yet - that was tomorrow's task), was wondering if in general there was any way to get Apache to display its live running config, rather than just parsing the files (as httpd -S seems to do).

Have tried Googling and searching here on ServerFault, but not found anything. I can imagine this might save a few people's bacon over time. :)

Pyromancer
  • 129
  • 3
  • 11

1 Answers1

6

This is how to recover Apache2 config from memory :


  1. grab the dump-all-memory-of-pid.sh script mentioned on this serverfault thread.

the Dump a linux process's memory to file

#!/bin/bash
grep rw-p /proc/$1/maps | sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p' | while read start stop; do gdb --batch --pid $1 -ex "dump memory $1-$start-$stop.dump 0x$start 0x$stop"; done
  • put this in a file (eg. "dump-all-memory-of-pid.sh") and make it executable
  • usage: ./dump-all-memory-of-pid.sh [pid]
  • The output is printed to files with the names: pid-startaddress-stopaddress.dump
  • Dependencies: gdb

  1. get the pid of your apache process

    pgrep -uroot apache2
    

  1. dump the process's memory

    mkdir /tmp/apache_dump && cd /tmp/apache_dump
    sh /path/to/dump-all-memory-of-pid.sh <PID>
    

  1. grep all of the dump files for something that you expect to be in the apache config file.

    grep DocumentRoot *
    

  1. open the matched dump file(s) in vim and search for the string.

    vim 24374-7f159d56c000-7f159d72c000.dump
    

Search by typing "/", eg "/DocumentRoot", then simply copy out the text that you want.


source : http://forums.whirlpool.net.au/archive/2189742

Froggiz
  • 3,013
  • 1
  • 18
  • 30