Archive for the ‘Linux’ Category

How to debug a segmentation fault caused by PHP

December 1st, 2009 4 comments

A segmentation fault can have many causes, the best thing to do when you have a segmentation fault is debug it to find out what’s causing it.

I explain to ways two do this.

With The GNU Debugger

  • First install the gdb package with apt-get or yum.
  • Second, stop all httpd processes
  • Start Apache in debug mode


httpd -X


apache2 -X
  • Find the parent process id from Apache


cat /var/run/


cat /var/run/
  • Start the gdb program
  • Connect the GNU debugger to the Apache process
attach <apache process id>
  • The debugger will halt the process, but we want to run it till the segmentation fault has happened
  • Now try to reproduce the segmentation fault. When this happens you will see the fault in the debugger.
  • To see what happened, get the backtrace

With Valgrind

  • Install valgrind with yum or apt-get
  • Stop all Apache processes
  • Start valgrind with Apache in debug mode


valgrind /usr/sbin/httpd -X


valgrind /usr/sbin/apache2 -X
  • Try to reproduce the segmentation fault and valgrind shows what happened

Redirect output to file

March 9th, 2009 No comments

Normally when you execute a command in your shell you’ll get the output direct on your screen. But it’s also possible to redirect this output to a file, for example for logging purposes.


php myscript.php > mylog.log

Now all output from myscript.php will go in the mylog.log file. This is called the “standard output” (stdout). But when a PHP error occurs it will not be written to the mylog.log file. Instead it will be printed on your screen. This is the “error output” (stderr), and to write this to mylog.log you have to use this:

php myscript 2>&1 mylog.log

This will send all output to mylog.log including the errors. It’s also possible to only write the error ouput to a log file.

php myscript 2> mylog.log

Combine this with ‘running processes as background jobs ‘ and you can run your scripts/command in the background but still be able to watch the progress in the log file.

php myscript 2>&1 mylog.log &

And now watch your log with

tail -f mylog.log

You will see new lines being written to the log in real time!

These different outputs are streams, read more info about this here.

Running processes as background jobs

March 2nd, 2009 1 comment

On a linux terminal you can simply run a process in the foreground like it normally does. But if you close your terminal session the process will stop running. If you run a large database import you don’t want to wait for it to finish, so you want to run it in the background.

To do this you can simply put a ‘&‘ behind the command you want to execute, for example:

mysql -u root -p < import.sql &

But it’s also possible to put a process to the background when it’s already running. You can do this with the keyboard shortcut ctrl + z. Then you ‘stop’ the process. You should see a message like this:

[1]+  Stopped                 mysql

Now you can choose two things, one is to run it in the foreground, the other is to run it in the background.
Just type bg <enter> and the process will continue running in the background. With fg <enter> it will run in the foreground.

You can see what processes are running in the back- or foreground with the command jobs.

Extend LVM with new physical disk

March 2nd, 2009 1 comment

LVM is a great tool for volume management. You can easily add a new (virtual) harddisk to a existing logical volume.
With fdisk -l you can see what devices are available. Choose the right one and execute:

fdisk /dev/sdb

Create a new partition which fills up all the free space with the type Linux LVM (HEX: 8e).
Then we create a physical volume for LVM:

lvm> pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created

After that we can extend the volume group with this new physical volume:

lvm> vgextend VolGroup00 /dev/sdb1
Volume group "VolGroup00" successfully extended

Then extend the existing logical volume with 100% of the free space from the new physical volume:

lvm> lvextend -l +100%FREE /dev/VolGroup00/os
Extending logical volume os to 27.84 GB
Logical volume os successfully resized

That’s all, the existing logical volume is now extended with the new harddisk.
If you have a ext3 filesystem on this logical volume you can extend this online using the command:

[[email protected] ~]# resize2fs /dev/VolGroup00/os
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/os is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/os to 7299072 (4k) blocks.
The filesystem on /dev/VolGroup00/os is now 7299072 blocks long.

Like I said before, this can be done on a online root filesystem without any problems. I’ve done it again this time. But always make sure to have a backup!

Commandline tips

February 20th, 2009 No comments

Do you think you know all great commands on the command-line? Then you have to take a look at this site. It’s a overview of the most used and most popular commands for linux.

Categories: Linux, Websites Tags: , ,

Developing on Ubuntu

February 9th, 2009 No comments

On my work I use a HP laptop with Ubuntu Intrepid. With Ubuntu and some nice applications you have a good platform for developing (web) applications.

These are the applications I use:

  • Firefox – Of course for surfing the internet, and with plugins like Firebug very useful for debugging javascript .
  • Thunderbird – My default mail client
  • Evolution – For access to my work calendar
  • KeePassX – For  storing passwords
  • Charles – A web debugging proxy
  • Geany – A fast text editor with a IDE
  • Meld Diff viewer – A diff and merge tool
  • RapidSVN – Front-end for subversion
  • Zend Studio – My most used IDE
  • Avidemux – A simple video editor with support for many codecs
  • Truecrypt – For securing important files
  • Dropbox – Used for the keepassx database, making it available on all my computers
  • VirtualBox – Running a Windows XP environment for testing with IE and using Visio (didn’t found a good alternative yet)

HP support pack on CentOS

February 7th, 2009 No comments

If you have CentOS running on a HP server you can install the HP support pack. On the HP site download the Redhat version.

First of all you need some rpm packages, this should be enough:

yum install rpm-build rpm-devel net-snmp glib kernel-devel
compat-libstdc++-296 make gcc

Than you have to edit the /etc/redhat-release file. First make a backup of the original file. Than place the following line in it:

Red Hat Enterprise Linux ES release 5

The version number must match the CentOS version, in my case this was CentOS 5.2.
After this you can easily start the installation by typing: ./install<versie>.sh -nui.

Extend a ext3 volume with LVM

February 7th, 2009 2 comments

If you have a ext3 volume on LVM you can easily change this volume.

When you want to extend a volume you can do this with lvextend.
To extend a volume with 10GB do the following:

[[email protected] ~]# lvextend -L+10G /dev/<volgroup>/<volume>
Extending logical volume <volume> to 14.88 GB
Logical volume <volume> successfully resized

After this you have to extend/resize the filesystem:

[[email protected] ~]# resize2fs /dev/<volgroup>/<volume>
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/os is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/os to 3899392 (4k) blocks.
The filesystem on /dev/VolGroup00/os is now 3899392 blocks long.

That’s all!
You can do this without any problems on a live root file system.

Less logging from snmpd

February 7th, 2009 No comments

The snmp deamon logs a lot to the syslog deamon on CentOS. Especially when you have some monitoring with the snmp protocol.

You can change this by editing the init options of snmpd. This options can be found in /etc/init.d/snmpd. Search for the rule starting with “OPTIONS=”


OPTIONS="-Ls d -Lf /dev/null -p /var/run/ -a"

You have to change this to:

OPTIONS="-LS 0-4 d -Lf /dev/null -p /var/run/ -a"

This says that you want to log everything with a priority above debug to the syslog deamon.

In CentOS and other Redhat distro’s you also can create a file /etc/snmp/snmpd.options and put the options line there.