Jul 28, 2010

Installing VirtualBox guest additions in a Debian guest

Heres' how I got VirtualBox guest additions installed in a Debian guest.

First you have to install the Linux kernel headers, gcc and make, which can be done with this one-liner (run as root):
apt-get install linux-headers-`uname -r` gcc make

Then mount the guest-additions by clicking "Devices" + "Install guest additions" on the VirtualBox menu:















Shortly after, a drive will mount on the desktop containing the guest additions:









open a terminal and, as root, run the appropriate installer for your system, like f.x:
sh /media/cdrom/VBoxLinuxAdditions-x86.run

Now the guest additions are built and installed. When it's done, just restart the virtual machine.

Apr 28, 2010

If connections from remote clients to MySQL are slow

MySQL attempts name resolving on remote connection and that can adversely impact performance.

I had a case where a client app written in Visual Basic, connecting via ODBC to a MySQL server running on Linux. It was abnormally slow. The VB app aquired a fresh connection upon every query and each query then took exactly 10 seconds to complete.
This smelled like a timeout scenario to me so I suspected a DNS lookup was taking place.

Adding the following config option to my.cnf solved the problem:
skip-name-resolve
It prevents MySQL from doing a DNS lookup of the remote clients IP adress.
Note that by using this option you can only use IP adresses (or "localhost") in the MySQL grants table.

More info at the MySQL site here:
http://dev.mysql.com/doc/refman/5.0/en/dns.html

Mar 19, 2010

Check all your PHP source files for errors

To recursively check all PHP source files at a given location:

find -name *.php -exec php -l -f {} \; | grep "Parse error:"

This shows which files have syntax errors, like this:
Parse error: syntax error, unexpected ';' in xyz.php on line 206

Dec 13, 2009

Tomcat and the mystery of the missing MySQL driver

If you have a Tomcat 5.x / MySQL app, upgrade the Tomcat version and it suddenly can't find the mysql driver - then this might apply to you.

If your project has a context.xml that explicitly names a datasource factory class like this:

<resource auth="Container" driverclassname="com.mysql.jdbc.Driver" factory="org.apache.commons.dbcp.BasicDataSourceFactory" name="jdbc/myDatabase" type="javax.sql.DataSource"/>
etc.. etc..

The "factory" attribute causes the problem on newer Tomcat's because they use their own factory class (org.apache.tomcat.dbcp.BasicDataSourceFactory) to deliver the datasource.
One solution that worked for me is:
  1. remove the "factory" attribute from your context.xml element.
  2. copy your mysql driver Jar into Tomcat's common/lib folder
  3. delete Tomcat's copy of your context.xml from Tomcat's conf\Catalina\localhost folder. It is recreated upon Tomcat start up and gets the same name as your app's .war file.

Netbeans and the frightfully forgetful class cache

While writing a unit tests in the brand flashing new NetBeans 6.8 it started complaining that the class under test was missing. No amount of code-completion magic nor import ingenuity would amend this. For all NetBeans could care - the class didn't exist. All that Netbeans would offer was to create a new class in the test source package... grrr.

Turns out that the Netbeans class cache can get a bit messed up after refactoring so the solution is simply to remove the cache folder and restart Netbeans.
  1. shut down Netbeans
  2. navigate to the cache index folder.
    • on linux it should live at:
      $HOME/.netbeans/6.8/var/cache/index
    • on Windows it's at:
      %USERPROFILE%\.netbeans\6.8\var\cache\index
  3. Remove the "index" folder
  4. Start NetBeans
This should apply to other versions of NetBeans also if you substitute the "6.8" in the paths with your version number.