Tuesday 31 May 2011

PHP FIXED: mysql_error() 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

If you are seeing the error above while running PHPUnit in Zend Studio, then I suggest you follow what I do. Here is my setup by the way: Ubuntu 11.04, Mysql 5.1.54.

Solution:

Just make a symbolic link from your mysql.sock to the directory it is looking:

ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

Friday 27 May 2011

HOW-TO: get Kraft working in Ubuntu 11.04

I was trying to set up a small business application called Kraft in Ubuntu. Everything installs fine, but when I tried to create a customer it doesn't allow me to select an address book. To all those out there who are struggling with this and can't go any further in the app, there is a fix for this. Apparently Kraft is based on KDE and it is expecting the app KAddressBook to be installed already. Problem is, Ubuntu doesn't come bundled with that initially and you have to get it yourself.

So open Ubuntu Software Center, and search for KAddressBook, download it, and restart Kraft. It should now work!

Wednesday 25 May 2011

PHP required_once(), include_once() errors

So I'm writing a Object Oriented webapp in PHP, and I have discovered a problem that hopefully the solution I found is useful to someone.

The Problem:

I have a front controller that delegates its tasks to a Service class, and that Service class has a few references to the domain objects. Here is my folder structure:

/var/www:
frontController.php
/var/www/service:
FruitService.php
/var/www/domain:
Apple.php
Orange.php  

Now in my FruitService.php, I originally had a couple of require_once() like so:

require_once('../domain/Apple.php');
require_once('../domain/Orange.php');

Seems reasonable right? WRONG! I spend about an hour trying to see why PHP fails with this nasty message:

PHP Warning:  require_once(../domain/Question.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in FruitService.php on line 2

PHP Warning:  require_once(../domain/Question.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in FruitService.php on line 2
It turns out that since your controller is serving the page, all the paths would have to be relative to that location of the controller. So in my example, this would work if I were to put it in FruitController.php:

require_once('domain/Apple.php');
require_once('domain/Banana.php');

However, this is a really bad idea since if you have another controller that uses the FruitController then your include path will break;

The formal solution would be to use the varible $_SERVER['DOCUMENT_ROOT'], so it would look like this:

require_once($_SERVER['DOCUMENT_ROOT'] . '/domain/Apple.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/domain/Apple.php');

Monday 23 May 2011

New shortcut in Ubuntu 11.04 to open a terminal

I had an interesting read about Ubuntu 11.04 and Unity located here http://askubuntu.com/questions/28086/unity-keyboard-mouse-shortcuts, and there is a pretty cool shortcut to open the terminal from anywhere.

Ctrl + Alt + T

will open a new Terminal basically from anywhere. Pretty cool. The only downsize is that Unity maps some of the common keystrokes that Eclipse also uses. I wish there was a way to configure Unity's keystrokes.

Saturday 21 May 2011

Problem with Ubuntu 11.04 when installing packages

If you are seeing something like this when installing / updating software:

Setting up tzdata (2011g-0ubuntu0.11.04) ...
Use of uninitialized value $reply in scalar chomp at /usr/share/perl5/Debconf/FrontEnd/Passthrough.pm line 66.
Use of uninitialized value $reply in concatenation (.) or string at /usr/share/perl5/Debconf/FrontEnd/Passthrough.pm line 67.
Use of uninitialized value $reply in split at /usr/share/perl5/Debconf/FrontEnd/Passthrough.pm line 68.
Use of uninitialized value $reply in scalar chomp at /usr/share/perl5/Debconf/FrontEnd/Passthrough.pm line 66.
Use of uninitialized value $reply in concatenation (.) or string at /usr/share/perl5/Debconf/FrontEnd/Passthrough.pm line 67.
Use of uninitialized value $reply in split at /usr/share/perl5/Debconf/FrontEnd/Passthrough.pm line 68.
Use of uninitialized value $reply in scalar chomp at /usr/share/perl5/Debconf/FrontEnd/Passthrough.pm line 66.
Use of uninitialized value $reply in concatenation (.) or string at /usr/share/perl5/Debconf/FrontEnd/Passthrough.pm line 67.
Use of uninitialized value $reply in split at /usr/share/perl5/Debconf/FrontEnd/Passthrough.pm line 68.
Use of uninitialized value $ret in string eq at /usr/share/perl5/Debconf/FrontEnd/Passthrough.pm line 109.
dpkg: error processing tzdata (--configure):

There is a solution that I did to fix this is to run this command in the command prompt:

 sudo dpkg-reconfigure tzdata

then follow the instructions to set the time zone. For some reason the Los Angeles timezone did not work out for me so I had to set it to the New York timezone. Then retry to to install the package and voila!