I have an Ubuntu VM running on my iMac at work. My code directory on my mac is accessible from my Linux VM server via NFS. Everything seem fine until when I needed to import a large database from our production server and got an error indicating that I had run out of space. I did a df -ah and saw that my sda1 partition was 100% full!

After googling a bit I ended up doing the following. I hope it helps someone out there who may encounter same problem.

The first thing I did was to power down my VM.
Next, I took advantage of Virtualbox’s VBoxManage command. In Windows you will have to execute VBoxManage.exe. The following command did the first part of the trick
VBoxManage modifyhd UbuntuVMBAse-disk1.vdi –resize 32768
When I ran Virtual box (without starting the VM) I checked the settings and sure enough the following was displayed;
Ubuntu VMBase-disk1.vdi (Normal 32.00GB)

Next, I needed to add the new space created to the partition I needed to expand. Enter Gparted.
I downloaded http://gparted.sourceforge.net/ ISO image.

I went to the settings of my VM and added the Gparted ISO to the storage settings (Make sure it is the first one in the list) I then ran the VM and it booted into Gparted live CD.

One difficulty you may encounter is that if you have a swap partition coming after the partition you want to expand, you most likely would see a light blue boundary surrounding it in the drives preview. What I did was to delete the swap partition first, and then I was able to expand the drive. I then added back the swap drive.

Finally I saved and then quit GParted. Removed itg from my storage settings and booted my VM. Voila! I now had my needed space.

Word of caution, Ensure that you have backed up relevant data before you do this. I did not need to because I had all my important data in a mapped drive. The worst would have been reinstalling my server apps and re-establishing my NFS shares.

Hope this helps someone!

I usually make some changes to my project and push to my GIT repository so that I can pull anywhere I am and work.

Recently, I made some changes at home which I pushed through then I made some changes at work which I did not push. Afterwards I made some further changes at home. By the time I wanted to update my working copy in the office, I got the error message,
$ git pull
'.error: Your local changes to the following files would be overwritten by merge'

I did not want to lose the changes I had made on my work computer so I had to find a way out. So what did I do?

Enter Git Stash. What does Stashing do? Stashing takes the dirty state of your working directory and saves it on a stack of unfinished changes that you can reapply at any time.

So I solved the problem I was having as follows;

1. $ git stash
Saved working directory and index state WIP on master: ebe7061 Image placeholder added

2. With a clean working copy I could not pull from master
$ git pull

3. Finally, I run the last command
$ git stash pop

What does git stash pop do? It removes a single stashed state from the stash list and apply it on top of the current working tree state

I hope this helps someone.

I recently had to work on a machine with an existing MySQL database running. Unfortunately, the person who installed MySQL had forgotten the root password.

If this happens to you, the first thing I will say is, ‘Don’t Panic!’. If you have root access to the server, then you are on your way, if not, then you will have to do this with someone who has root access.

Step 1.  Shut down MySQL. This differs from one OS to another. The example here is on Ubuntu 12.04.

/etc/init.d/mysql stop

Step 2.  Start up MySQL in safe mode

mysqld_safe --skip-grant-tables &

Step 3.  Log in to mysql as root without the -p option

mysql -u root

Step 4.  Update the root password and flush privileges

mysql> update user set password=PASSWORD("new password") where User='root';
mysql> flush privileges;
mysql> quit;

Step 5. Stop and Start  MySQL

/etc/init.d/mysql stop

/etc/init.d/mysql start

Login with your new password.


First let me say that using Static functions in an OOP based PHP project is a bad idea.

The purpose for this article is to help with those who like me may find themselves having to write tests for legacy systems or code inherited from others.

Let’s say for instance you have a cache class that has static functions to manage Memcached objects. How do test that?

The way to go is by Mocking the static methods. This is better understood with code than words.

Assuming you have a Cache class

class Cache {

public static function getCache($key)
$client = new Memcached();
$client->addServer( '', 11211 );
if( ! isset( $servers[''] ) )
Cache::error( 'Cache::GetInstance() : Unable to add server' );

$value = $client->get($key)
//do we have a value? If yes, return to client

if( $res_code == Memcached::RES_SUCCESS )
return $value;
} else{
Cache::error('Unable to get data for ' . $key);
return null


Now to test the above function, we need to mock the class as well as the method getCache,

class CacheTest extends PHPUnit_Framework_TestCase {

public function testGetCacheInstance()
$class = $this->getMockClass(


$this->assertEquals('yes', $class::Get('mykey'));

This will work in PHP5.3 or newer as well as PHPUnit 3.6.

For more on Mock Objects, please read the PHPUnit Manual http://www.phpunit.de/manual/3.0/en/mock-objects.html

Another helpful article is Testing Code that uses Singletons by Sebastian Bergmann http://sebastian-bergmann.de/archives/882-Testing-Code-That-Uses-Singletons.html

New Line in PHP CLI

Steve Popoola —  May 29, 2012 — 1 Comment

For many new to PHP and even for experienced once, sometimes you experience some weird behaviour and wonder why it happens? It is usually because we have not taken time to read the PHP documentation to know how specific command work and some of the behaviour we should expect of not used properly.

Once of such is the echo command. The echo command prints out to the console or page, the string delimited by single or double quotes.
for exampple;
echo 'This is a string'

Will output, This is a string.

It is usual for developers to use Escape sequences \n for linux and \r\n for Windows to break the string into lines.

The problem arises when you use single quotes to wrap these characters.
Take for example;

echo 'This is line 1 \n This is line 2';

This will output the unexpected result, This is line 1\nThis is line 2

The reason is that Escape sequences are only parsed when they are inside double quotes.

The above will work as follows;

echo "This is line 1 \n This is line 2";

This is line 1
This is line 2

Don’t forget to read the PHP Manual! http://php.net/manual/en/language.types.string.php

SVN Post Commit

Steve Popoola —  May 24, 2012 — 1 Comment

When working with a team of developers on the same project, you want to be abreast of what others are doing. One nifty way of acheiving this is through the use of post commit hooks. These hooks are available in most Version Control Systems but in this blog, I will be showing you how to create one in Subversion.

In your svn repository directory is one named ‘hooks’. This is the where all the various hooks that subversion executes if enabled. One of the hooks we will be looking at is the post-commit hook. The file name should be, you guessed right, post-commit.

Let us set up a post-commit hook to send emails once a commit is made to the repository.

In your hooks directory is a file called post-commit.tmpl. Rename this to post-commit.

Replace the contents of the file with the following;
REPOS="$1" # repository path
REV="$2" # revision number
echo "successfully committed to $REV"

This will send the above message back to the client once the file(s) is/are successfully committed.

What if you wanted to send email notification? Easy, all you need is svnnotify.

For you to use svnnotify, it must be installed first. For Ubuntu Linux, you can do the following;

sudo apt-get install libsvn-notify-perl

You also need to ensure that you have sendmail set up. If you issue the command;

which sendmail

You should see something like /usr/sbin/sendmail. If not, then you need to install sendmail with sudo apt-get install sendmail
With that out of the way, we are now ready to add email notification to our post-commit hook
Open your post-commit file;

sudo vi post-commit

Add the following;

TO="me@myteam.com" # notifications email
FROM="myrep@myteam.com" # "FROM" fields
svnnotify --repos-path "$REPOS" --revision "$REV" --to "$TO" --from "$FROM" --with-diff --handler HTML::ColorDiff --subject-cx --subject-prefix 'MYREPO'

Voila! You have your post-commit email with a nice, well formatted diff of your files.

When I did this in my team, I noticed that svn commits were slow to complete because it was waiting for the post-commit to complete. I got around this by adding a delay to the email notification so that svnnotify runs after the commit is complete.

I did this by wrapping the svnnotify in a function call as follows;

delayed_notify( ) {
sleep 10
svnnotify --repos-path "$REPOS" --revision "$REV" --to "$TO" --from "$FROM" --with-diff --handler HTML::ColorDiff --subject-cx --subject-prefix 'MYREPO'
delayed_notify $1 $2 > /dev/null 2>&1 &

You can test by running the script from the command line. The number is the last revision of the repository;
./post-commit /var/svn/repos/myrepo/ 20

Sometimes you may have the need to remove a project directory from version control. I had to do same too recently and had to find a quick way to do it.  The example here is for Linux as that is what I use as my development environment.

You can use the following command and I will try to explain what it does.
find ./ -name .svn -exec rm -rf '{}' ';'

Find is used to search for a a file, directory or symlink based on come criteria or pattern. In this case we are executing a command which says, ‘find within the current directory and it’s children, any pattern with .svn and execute the command ‘rm -rf’ which removes  the directory and delete it’s contents.  By default, the find command is recursive, meaning it searches the current directory and it’s subdirectories.

I decided to put this on my blog as a reminder and I hope this helps someone.

There is no doubt that the two most used and popular Versioning Control Systems (VCS) are Subversion and Git.

In any project where you have teams working with the same documents (Porject teams, developers, etc)  the need for a versioning control system cannot be overemphasized.

Having worked with both Subversion and Git, I have decided to share the steps required to install these two systems. Although they can be installed on any OS, I am assuming a Linux operating system, since that is the one I often use  and quite familiar with.

Continue Reading…

I have been scratching my head trying to resolve the issues arising from implementing a Continuous Integration setup for a Zend Framework project using Phing and PHPUnit.

What should have been a straight forward exercise turned into a head scratching one and after hours of visiting the PHPUnit and Phing manual, I did not have an answer to the problem. Then I saw a bug entered on the Zend Framework Issue Tracker and there it was!

Continue Reading…

One of this challenges that often face established websites is that at some point, the decision is made to rebuild parts or all of the site. Such changes need to be made with care, in order not to cause loss of revenue to the business owners.

One of the changes that is very critical to the business is the url structure of the site. Any changes made to to the Urls,  could significantly affect the business because previous urls would have been crawled by search angines and when someone searches for something that is on your site but visits with the search engine cached url, that potential customer will be greeted with a 404 page and he or she may not bother trying to navigate to your home page when many other competitor sites are readily available with the same product.

There are different ways to handle this problem. One is creating a 301 redirection in the web server configuration. However, for a large sites, sticking lots of urls in the webserver config soon becomes messy and unruly. What other option is there?

Continue Reading…