Category: "Linux stuff"

How to log request processing times in Apache

If you have an apache (2) web server, you probably have an access.log file showing you all kinds of data using the “combined” log format. Let’s see how to include processing time into that log file.

By default a line in the combined log looks like this:

[codeblock lang="” line="1″]10.0.209.80 - - [03/Dec/2009:03:20:47 +0100] “GET /info-tech/ HTTP/1.1″ 200 46482 “http://fplanque.com/info-tech/” “Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5″[/codeblock]

Notice the 2 dashes - - just after the IP. The first one stands for “I could not identify the user using ident” and the second one for “no user authentication was performed".

Now, let’s face it: you will never identify anyone using ident. Your apache conf probably even doesn’t try. That field is a left over from ancient times. So let’s replace that first dash with something useful, i-e: the processing time of the request! Note that by doing this we keep the global structure of the file identical and any log processing tool you might be using should not be affected.

Read more »

How to install the APC PHP Cache on Debian (Lenny or Squeeze)

How to install the APC PHP Cache on Debian (Lenny or Squeeze)
The APC PHP Cache Control Panel

The APC cache can significantly improve your PHP script performance, just by installing it, which basically takes 5 minutes! (Plus, it’s actually supported by the core PHP developers and will probably be integrated into PHP6…)

Here’s what I did on my Debian Lenny box…

First you may want to have a reference benchmark to see if it actually improves:

Code

ab -c5 -n100 http://www.yoursite.com/yourscript.php

Now install the APC package:

Code

aptitude install php-apc

Now, restart apache:

Code

/etc/init.d/apache2 restart

Now, you can run your benchmark again and see the difference! Tada! :)

Read more »

How to fix apt-get missing keys (Debian)

Lately, my Debian servers have been bugging me with stuff like this everytime I tried to apt-get update:


W: There are no public key available for the following key IDs:
XYZ123
W: You may want to run apt-get update to correct these problems</p>

and it tells you to ap-get update to solve the problem, which is of little help, since that is what caused the problem in the first place!

Here's the solution:

Code

# gpg --keyserver wwwkeys.eu.pgp.net --recv-keys XYZ123

Don't forget to replace XYZ123 with the actual missing key.

Code

# apt-key add /root/.gnupg/pubring.gpg

Code

# apt-get update

How to use SSH private keys on Mac OS X

First cool thing that everybody knows already: Mac OSX is based on Unix so you get ssh out of the box.

Second cool thing you may not know: OS X 10.5 actually also comes with an ssh key agent (ssh-agent). That means that, without any additional software (like PuTTY Agent on Windows...), Mac OSX can actually load an encrypted private key into memory and remember it for all subsequent connections...

Third cool thing that almost seems too good to be true: ssh-agent can store the passwords of the encrypted keys into your keychain. Than means that you have to tell it once to remember the decryption password for your key(s) like this:

ssh-add -K .ssh/id_whatever_your_rivate_key_is

And next time you log into your mac and try to ssh somewhere, your private key will be loaded automagically (as long as your keychain is unlocked of course).

Very groovy!!

How to manage MySQL binary log space (Debian)

So it turns out that what is filling up my root partition is my MySQL binary logs.

A collection of fat files in /var/log/mysql ...

So I had several options:

  • Move the logs to a different partition
  • Increase the size of the root partition
  • Decrease the size of the logs

The first option is probably the most reasonable one. But since I had other plans for the evening I actually went with the last option: decreasing the size of the logs! :roll:

The magic conf is located in /etc/mysql/my.cnf and the magic line is:

Code

expire_logs_days = 5

It was set to 10 but I have no idea why I even need 5 days. Aren't those logs only useful until transactions commit to disk, and replication executes. Oh maybe if you have replicated slaves more than 5 days behind the master??

Edit 2009: You can purge the logs up to a specific file with a statement like this:

Code

PURGE BINARY LOGS TO 'mysql-bin.000666';