Extremist Developer

RSS

Posts tagged with "apache"

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. 

Extracting infos from Apache access log

In the process of writing a “log watcher” to plug in with Live Graph, i needed to extract all the info from an access log. Assuming we have the standard access log from Apache:

172.16.10.23 - - [29/Oct/2010:10:39:51 -0400] “GET / HTTP/1.1” 200 10890 “-” “Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7”

So assuming i want to extract: IP, Date, Method, HTTP Code, Bytes sent and Use-agent, here is the Regex that does the trick for me:

(\b\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\b)\s-\s-\s(.*)\s”([A-Z]*)\s\/\s[A-Z]+\/[0-9].[0-9]”\s(\d{1,3})\s([0-9]+)\s”-“\s”(.*)”

Might not be the best Regex to do so, but does the trick pretty good. 

As a side note, i use NodeJS to write the log watcher, and i gotta admit, it’s pretty amazing. Gonna post soon about it.