For Gentoo Linux, do the following (adjust where necessary):
0. Make sure you have an ATX board and a power button ;)
1. Make sure your kernel has support for ACPI (either built-in or as modules)
2. # emerge acpi acpid
3. # rc-update add acpid default
4. for kernel 2.6 (skip this step if ACPI support is compiled into the kernel):
# echo “ac” >>/etc/modules.autoload.d/kernel-2.6
# echo “button” >>/etc/modules.autoload.d/kernel-2.6
5. add parameters apm=off and acpi=on to your kernel boot line (e.g. in /boot/grub/menu.lst)
6. # reboot
(Source: Linux für alle. Thanks to maol for the pointer; other interesting articles: Server shutdown via Apache [Caution!], LaTeX Business cards)