Archive for February, 2013

phpVirtualBox in PHP vs RPM battle

February 13, 2013 Leave a comment

Is there no standard anymore?
What it takes, who I am, where I’ve been
You can’t be something you’re not
Be yourself, by yourself
Stay away from me
A lesson learned in life
Known from the dawn of time

(Pantera – Walk)

phpVirtualBox is a great piece of software that enables you to access, control and administer remote VirtualBox instances in a headless environment. So far, I was deploying it simply by downloading zip file, unzipping in /var/www/html and setting appropriate apache configuration. But, as a struggle to move my infrastructure (including my own workstation, desktop, dev servers, etc) to Puppet, I decided it was time to give yet another day of my life to open source community. Although I didn’t plan it will take that long to package phpVirtualBox properly, it did in the end.
There were some already available packages out there, but they were bad… So I decided to take a peak how EPEL packages php applications – like MediaWiki. At EPEL site, I downloaded mediawiki119 source RPM, unpackaged it and took a peak.

Idea was simple: all the static content (php code, images, js…) goes into /usr/share/, while all the dynamic content (user data, config.php…) goes into /var/www/.

This allows us to use the same code for multiple instances of the application. So, I’ve tried to follow that path. But soon enough, thing started to break apart. No matter what I did, app always wanted to read /usr/share/phpvirtualbox-4.2/config.php …

After dissecting the code, I’ve found out why. Application was trying to use php dirname() function to find out the parent directory of the php script, and with that information it was supposed to find relative location of config.php. Offending line was:


After talking to few of my dear collegues that are PHP programmers, I’ve found out that dirname() doesn’t respect symlinks, in a way that will always return location of the symlink target. So I had to find another approach. Function readlink() couldn’t help either – because scripts weren’t links, but their parrent directories were :-/ Ah crap. After two hours of fiddling with PHP (sorry – I’m a newbie at this language), I figured it out, and changed the line accordingly. This is what it looks like now:


As a true open source warrior, I’ve paid my due with reporting both SPEC file, finished src.rpm & rpm, and posting the patch upstream:

Hope you enjoy it!

%d bloggers like this: