Debugging PHP-App Hosted in VirturalBox CentOS VM Using Netbeans

Setting up debugging locally on one machine (both Netbeans and xdebug on the same host) is easy enough. However, if you want to connect Netbeans to a xdebug over to a guest virtual machine, it will require a bit of work, but not hard.

My host machine is Windows 7 and running a CentOS virtual machine inside VirtualBox. The following was what I did to get it running.

Firstly I installed C and C++ compilers, which comes in the “Development Tools”

$ sudo yum groupinstall 'Development Tools'

then I installed php-devel which would give me phpize (which is required by pecl when installing xdebug)

$ sudo yum install php-devel

Now I was ready to install xdebug:

$ sudo pecl install xdebug

Once that was done, I updated php.ini file to enable xdebug. Find the xdebug section in php.ini file, if no, create one section for it under /etc/php.ini



xdebug.remote_enable  = On
xdebug.remote_host    =
xdebug.remote_port    = 9000
xdebug.remote_handler = dbgp
xdebug.remote_mode    = req

xdebug.remote_connect_back = On
xdebug.idekey = "netbeans-xdebug"
xdebug.remote_log = /tmp/xdebug.log

You will need to find the path to file by running:

find / -name

Yours might be different from mine.

Now I was ready to enable xdebug in Netbeans, which was running on the host machine (Windows 7 in my case). Under Tools > Options > PHP > Debugging:

Debugger Port: 9000
Session ID: netbeans-xdebug

Under Project Properties (right click on project root in the Project window) > Run Configuration:

Run as: Local Web Site (running on local web server)
Project URL: http://localhost:8080/ Index file: index.php

(I have setup port forwarding from 8080 on my localhost to port 80 on my virtual machine)

Under Project Properties > Run Configuration > Advanced

Debug URL: Default: http://localhost:8080/index.php
Path Mapping:
Server Path: /path/to/project/in/guest
Project Path: /path/to/project/in/host/

That’s it, now I am able to start setting break points and press Ctrl + F5 to start debugging in Netbeans over the virtual machine.

Recovering Windows Boot Loader in GRUB

I have two disks with two different OSes installed on each – one for Windows XP and one for Fedora 19. They work happily with each other and don’t cause any issues.

Two weeks ago, I decided to upgrade Windows XP to Windows 7. Installation worked fine, Windows 7 boots without problems (although I need to unplug the Fedora disk because Windows 7 just couldn’t allow me to proceed with the installation with two disks connected).

However, when I re-plugged the other disk back and boot from Fedora as usual, Windows won’t start if I select it from the GRUB menu (I already suspected this problem before I tried to upgrade Windows).

The simplest solution is to re-install Fedora again and the installer should be able to pick up the new Windows 7 without problems, but I will have to re-install everything under Fedora, which is not desired.

To fix this issue, I followed the following steps:

1. Find out the UUID in the Windows partition. In most cases (and in my case too), it is /dev/sda1, to be sure, you can run “gdisk” as root:

[root@localhost]# gdisk -l /dev/sda

GPT fdisk (gdisk) version 0.8.8

Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present

Disk /dev/sda: 1953523055 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 39402158-CA16-42CC-AC6F-2320B82B2498
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953523021
Partitions will be aligned on 8-sector boundaries
Total free space is 6979 sectors (3.4 MiB)

Number Start (sector) End (sector) Size Code Name
1 2048 104855551 50.0 GiB 0700 Microsoft basic data
5 104857264 167771286 30.0 GiB 0700 Microsoft basic data
6 167771583 1006633151 400.0 GiB 0700 Microsoft basic data
7 1006633215 1953520127 451.5 GiB 0700 Microsoft basic data

My Windows is installed on the 50GB partition, which is the first one.

2. Seondly, I needed to find the UUID for this partition, run

[root@localhost]# blkid /dev/sda1

/dev/sda1: UUID="0C6E54886E546C88" TYPE="ntfs"<

3. Finally I need to update the grub.cfg file with the new UUID. Open file /boot/grub2/grub.cfg, and scroll to the part that have Windows information

### BEGIN /etc/grub.d/30_os-prober ###
menuentry 'Microsoft Windows (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-chain-16D8D903D8D8E253' {
insmod part_msdos
insmod ntfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 16D8D903D8D8E253
search --no-floppy --fs-uuid --set=root 16D8D903D8D8E253
drivemap -s (hd0) ${root}
chainloader +1
### END /etc/grub.d/30_os-prober ###

Simply replace “16D8D903D8D8E253” with “0C6E54886E546C88”,

### BEGIN /etc/grub.d/30_os-prober ###
menuentry 'Microsoft Windows (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-chain-0C6E54886E546C88' {
insmod part_msdos
insmod ntfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 0C6E54886E546C88
search --no-floppy --fs-uuid --set=root 0C6E54886E546C88
drivemap -s (hd0) ${root}
chainloader +1
### END /etc/grub.d/30_os-prober ###

then reboot your computer.

Now you should be able to select the Windows entry from the GRUB menu in the boot up.

Change Startup Programs in Gnome 3 Under Fedora

I recently installed Fedora 19 as a replacement for Ubuntu 13.04 as somehow Ubuntu won’t start and I would like to have a new taste to see what Fedora looks after a few years without using it.

Installation went successfully without problems and I also managed to install Cairo Dock. The problem is that Cairo Dock won’t start when Gnome starts, unlike Ubuntu. I am not sure the reason behind it, but to change it, simply using command “gnome-session-properties” to add it to the list of start up programs. Of course, you need to be root first.


It is not obvious if you don’t know where to look for it.

Hope this helps.

VirtualBox Shared Folders with CentOS Server Guest

I have recently switched from MacBook Pro to Mac Mini for my development machine and I have also switched from VMWare to VirtualBox simply for the sake of OpenSource. Because the new Mac Mini gives me 16GB of DDR3 RAM, which gives me the power to run my own virtual server machine as my sandbox to develop on. To make my life a bit easier, I want to share my coding folder on Mac Mini with the server in the virtual machine, so that I don’t need to keep syncing files manually. Luckily VirtualBox supports this, but need a bit of work to get it going.

In this article I will be creating a shared folder within VirtualBox that will link my /Users/ericlin/Projects directory with one on the CentOS box under /mnt/projects.

Firstly, within VirtualBox, select the guest machine you wish to contain the shared folder.

Press the Settings button and choose the folder that you want to share on your host machine, and give appropriate access level:

Start your guest machine and login as normal.

Select Devices -> Install Guest Additions, this will insert an iso image into the CDROM, but we need to mount it manually:

sudo mkdir /media/cdrom
sudo mount /dev/cdrom /media/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only

Now if you do “ls” on /media/cdrom, you will see the following contents:

Run file “” to install the addition:

sudo /media/cdrom/

Running it the first time I got the following error:

To fix it, simply do what it asks you to do:

yum install kernel-devel-2.6.32-279.el6.x86_64

Wait for it to finish and try again with previous command:

sudo /media/cdrom/

Don’t worry about the FAILED message in the last line, we are running the server version, not the desktop version, so no Window System is required. Once everything is finished, reboot the virtual machine:

sudo reboot

Lastly, you just need to mount the folder. I created the directory that is going to be mounted to: /mnt/projects

sudo mkdir /mnt/projects

Now you just need to mount the shared folder to the newly created directory using the following command.

sudo mount –t vboxsf /Users/ericlin/Projects /mnt/projects

Then you should be able to

cd /mnt/projects
ls -sh

If you want the foler to be mounted automatically on start up, add the following line to your /etc/fstab file:

Projects        /home/ericlin/em    vboxsf    defaults    0 0

ZIP Incompatibility Issue: Need PK compat. v4.5 (can do v2.1)

Today I downloaded a zip file from one of our clients at work and tried to unzip the archive file, however, I got the following error:

$ unzip
   skipping: test.csv  need PK compat. v4.5 (can do v2.1)

To solve this issue, I had to install p7zip.

On Red Hat/CentOS, use yum:

$ sudo yum install p7zip

On Ubuntu, use apt-get:

$ sudo apt-get install p7zip

And then use command 7za to extract the file:

$ 7za e
7-Zip (A) [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,2 CPUs)

Processing archive:

Extracting  test.csv

Everything is Ok

Size:       56433
Compressed: 7529